pseudo-localization
Advanced tools
Comparing version 1.1.1 to 1.1.2
34
index.js
@@ -67,18 +67,16 @@ const pseudoLocalization = (() => { | ||
const textNodesUnder = element => { | ||
let n; | ||
const a = []; | ||
const walk = document.createTreeWalker( | ||
const walker = document.createTreeWalker( | ||
element, | ||
NodeFilter.SHOW_TEXT, | ||
node => { | ||
const isAllWs = !/[^\s]/.test(node.nodeValue); | ||
// A comment node or a text node, all whitespace | ||
const isIgnorable = | ||
node.nodeType == 8 || (node.nodeType == 3 && isAllWs); | ||
if (isIgnorable) return NodeFilter.FILTER_REJECT; | ||
const isAllWhitespace = !/[^\s]/.test(node.nodeValue); | ||
if (isAllWhitespace) return NodeFilter.FILTER_REJECT; | ||
return NodeFilter.FILTER_ACCEPT; | ||
} | ||
); | ||
while ((n = walk.nextNode())) a.push(n); | ||
return a; | ||
let currNode; | ||
const textNodes = []; | ||
while ((currNode = walker.nextNode())) textNodes.push(currNode); | ||
return textNodes; | ||
}; | ||
@@ -88,13 +86,14 @@ | ||
let pseudoLocalizedText = ""; | ||
for (let c of string) { | ||
if (map[c]) { | ||
for (let character of string) { | ||
if (map[character]) { | ||
pseudoLocalizedText += | ||
map[c][Math.floor(Math.random() * map[c].length)]; | ||
} else pseudoLocalizedText += c; | ||
map[character][Math.floor(Math.random() * map[character].length)]; | ||
} else pseudoLocalizedText += character; | ||
} | ||
const explodeRatio = 1.4; | ||
const explodedTextLength = Math.ceil(string.length * explodeRatio); | ||
// Trim strings to prevent whitespace from increasing the explosion amount | ||
const explodedTextLength = Math.ceil(string.trim().length * explodeRatio); | ||
let i = 0; | ||
while (pseudoLocalizedText.length < explodedTextLength) { | ||
while (pseudoLocalizedText.trim().length < explodedTextLength) { | ||
pseudoLocalizedText += " " + explosionSymbols[i++]; | ||
@@ -114,3 +113,2 @@ } | ||
const domMutationCallback = mutationsList => { | ||
console.log(mutationsList); | ||
for (var mutation of mutationsList) { | ||
@@ -137,3 +135,3 @@ if (mutation.type === "childList" && mutation.addedNodes.length > 0) { | ||
} | ||
} | ||
}; | ||
@@ -140,0 +138,0 @@ // Observe dom update and pseudo localize changed nodes. |
{ | ||
"name": "pseudo-localization", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Dynamic pseudo-localization in the browser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
385441
144