New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pseudo-localization

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pseudo-localization - npm Package Compare versions

Comparing version 1.1.5 to 1.2.0

localize.js

3

CHANGELOG.md

@@ -0,1 +1,4 @@

## 1.2.0
- Expose `localize` function
## 1.1.5

@@ -2,0 +5,0 @@ - Fix typo in README

164

index.js

@@ -0,119 +1,4 @@

const psuedoLocalizeString = require('./localize');
const pseudoLocalization = (() => {
const ACCENTED_MAP = {
a: "ȧ",
A: "Ȧ",
b: "ƀ",
B: "Ɓ",
c: "ƈ",
C: "Ƈ",
d: "ḓ",
D: "Ḓ",
e: "ḗ",
E: "Ḗ",
f: "ƒ",
F: "Ƒ",
g: "ɠ",
G: "Ɠ",
h: "ħ",
H: "Ħ",
i: "ī",
I: "Ī",
j: "ĵ",
J: "Ĵ",
k: "ķ",
K: "Ķ",
l: "ŀ",
L: "Ŀ",
m: "ḿ",
M: "Ḿ",
n: "ƞ",
N: "Ƞ",
o: "ǿ",
O: "Ǿ",
p: "ƥ",
P: "Ƥ",
q: "ɋ",
Q: "Ɋ",
r: "ř",
R: "Ř",
s: "ş",
S: "Ş",
t: "ŧ",
T: "Ŧ",
v: "ṽ",
V: "Ṽ",
u: "ŭ",
U: "Ŭ",
w: "ẇ",
W: "Ẇ",
x: "ẋ",
X: "Ẋ",
y: "ẏ",
Y: "Ẏ",
z: "ẑ",
Z: "Ẑ"
};
const BIDI_MAP = {
a: "ɐ",
A: "∀",
b: "q",
B: "Ԑ",
c: "ɔ",
C: "Ↄ",
d: "p",
D: "ᗡ",
e: "ǝ",
E: "Ǝ",
f: "ɟ",
F: "Ⅎ",
g: "ƃ",
G: "⅁",
h: "ɥ",
H: "H",
i: "ı",
I: "I",
j: "ɾ",
J: "ſ",
k: "ʞ",
K: "Ӽ",
l: "ʅ",
L: "⅂",
m: "ɯ",
M: "W",
n: "u",
N: "N",
o: "o",
O: "O",
p: "d",
P: "Ԁ",
q: "b",
Q: "Ò",
r: "ɹ",
R: "ᴚ",
s: "s",
S: "S",
t: "ʇ",
T: "⊥",
u: "n",
U: "∩",
v: "ʌ",
V: "Ʌ",
w: "ʍ",
W: "M",
x: "x",
X: "X",
y: "ʎ",
Y: "⅄",
z: "z",
Z: "Z"
};
let opts = {
prefix: "",
postfix: "",
map: ACCENTED_MAP,
elongate: true
};
const textNodesUnder = element => {

@@ -136,31 +21,6 @@ const walker = document.createTreeWalker(

const psuedoLocalizeString = string => {
let pseudoLocalizedText = "";
for (let character of string) {
if (opts.map[character]) {
const cl = character.toLowerCase();
// duplicate "a", "e", "o" and "u" to emulate ~30% longer text
if (
opts.elongate &&
(cl === "a" || cl === "e" || cl === "o" || cl === "u")
) {
pseudoLocalizedText += opts.map[character] + opts.map[character];
} else pseudoLocalizedText += opts.map[character];
} else pseudoLocalizedText += character;
}
// If this string is from the DOM, it should already contain the pre- and postfix.
if (
pseudoLocalizedText.startsWith(opts.prefix) &&
pseudoLocalizedText.endsWith(opts.postfix)
) {
return pseudoLocalizedText;
}
return opts.prefix + pseudoLocalizedText + opts.postfix;
};
const pseudoLocalize = element => {
const pseudoLocalize = (element, options) => {
const textNodesUnderElement = textNodesUnder(element);
for (let textNode of textNodesUnderElement) {
textNode.nodeValue = psuedoLocalizeString(textNode.nodeValue);
textNode.nodeValue = psuedoLocalizeString(textNode.nodeValue, options);
}

@@ -201,13 +61,4 @@ };

const start = (options = { strategy: "accented" }) => {
if (options.strategy === "bidi") {
// Surround words with Unicode formatting marks forcing
// the RTL directionality of characters.
opts.prefix = "\u202e";
opts.postfix = "\u202c";
opts.map = BIDI_MAP;
opts.elongate = false;
}
pseudoLocalize(document.body);
const start = (options) => {
pseudoLocalize(document.body, options);
observer.observe(document.body, observerConfig);

@@ -222,3 +73,4 @@ };

start,
stop
stop,
localize: psuedoLocalizeString,
};

@@ -225,0 +77,0 @@ })();

{
"name": "pseudo-localization",
"version": "1.1.5",
"version": "1.2.0",
"description": "Dynamic pseudo-localization in the browser",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -71,2 +71,14 @@ <sub>Inspired by pseudo-localization at [Netflix](https://medium.com/netflix-techblog/pseudo-localization-netflix-12fff76fbcbe) and [Firefox](https://reviewboard.mozilla.org/r/248606/diff/2#index_header)</sub>

You can also call the underlying `localize` function to pseudo-localize any string.
```js
import { localize } from 'pseudo-localization';
// OR
import localize from 'pseudo-localization/localize';
console.log(localize('hello')); // --> ħḗḗŀŀǿǿ
console.log(localize('hello', { strategy: 'bidi' })); // --> oʅʅǝɥ
```
## Strategies

@@ -73,0 +85,0 @@ `pseudo-localization` supports two strategies:

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc