pseudo-localization 2.2.2 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,8 +38,13 @@ import pseudoLocalization from 'pseudo-localization';
38
38
 
39
39
  pseudoLocalization.start();
40
40
 
41
+ pseudoLocalization.isEnabled // true
42
+
41
43
  // Later, if needed
42
44
  pseudoLocalization.stop();
45
+
46
+ pseudoLocalization.isEnabled // false
47
+
43
48
  ```
44
49
 
45
50
  To use `pseudo-localization` in React, Vue, Ember or anything else, hook the `start` and `stop` methods into your libraries
package/lib/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"localize",{enumerable:true,get:function get(){return _localize.default}});exports.default=void 0;var _localize=_interopRequireDefault(require("./localize.js"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _createForOfIteratorHelper(o,allowArrayLike){var it=typeof Symbol!=="undefined"&&o[Symbol.iterator]||o["@@iterator"];if(!it){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;var F=function F(){};return{s:F,n:function n(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]}},e:function e(_e){throw _e},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var normalCompletion=true,didErr=false,err;return{s:function s(){it=it.call(o)},n:function n(){var step=it.next();normalCompletion=step.done;return step},e:function e(_e2){didErr=true;err=_e2},f:function f(){try{if(!normalCompletion&&it.return!=null)it.return()}finally{if(didErr)throw err}}}}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i]}return arr2}var pseudoLocalization=function(){var opts={blacklistedNodeNames:["STYLE"]};var observer=null;var observerConfig={characterData:true,childList:true,subtree:true};var textNodesUnder=function textNodesUnder(element){var walker=document.createTreeWalker(element,NodeFilter.SHOW_TEXT,function(node){var isAllWhitespace=!/[^\s]/.test(node.nodeValue);if(isAllWhitespace)return NodeFilter.FILTER_REJECT;var isBlacklistedNode=opts.blacklistedNodeNames.includes(node.parentElement.nodeName);if(isBlacklistedNode)return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT});var currNode;var textNodes=[];while(currNode=walker.nextNode()){textNodes.push(currNode)}return textNodes};var isNonEmptyString=function isNonEmptyString(str){return str&&typeof str==="string"};var pseudoLocalize=function pseudoLocalize(element){var textNodesUnderElement=textNodesUnder(element);var _iterator=_createForOfIteratorHelper(textNodesUnderElement),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var textNode=_step.value;var nodeValue=textNode.nodeValue;if(isNonEmptyString(nodeValue)){textNode.nodeValue=(0,_localize.default)(nodeValue,opts)}}}catch(err){_iterator.e(err)}finally{_iterator.f()}};var domMutationCallback=function domMutationCallback(mutationsList){var _iterator2=_createForOfIteratorHelper(mutationsList),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var mutation=_step2.value;if(mutation.type==="childList"&&mutation.addedNodes.length>0){observer.disconnect();mutation.addedNodes.forEach(pseudoLocalize);observer.observe(document.body,observerConfig)}else if(mutation.type==="characterData"){var nodeValue=mutation.target.nodeValue;var isBlacklistedNode=opts.blacklistedNodeNames.includes(mutation.target.parentElement.nodeName);if(isNonEmptyString(nodeValue)&&!isBlacklistedNode){observer.disconnect();mutation.target.nodeValue=(0,_localize.default)(nodeValue,opts);observer.observe(document.body,observerConfig)}}}}catch(err){_iterator2.e(err)}finally{_iterator2.f()}};var start=function start(){var _ref=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},_ref$strategy=_ref.strategy,strategy=_ref$strategy===void 0?"accented":_ref$strategy,_ref$blacklistedNodeN=_ref.blacklistedNodeNames,blacklistedNodeNames=_ref$blacklistedNodeN===void 0?opts.blacklistedNodeNames:_ref$blacklistedNodeN;opts.blacklistedNodeNames=blacklistedNodeNames;opts.strategy=strategy;pseudoLocalize(document.body);observer=new MutationObserver(domMutationCallback);observer.observe(document.body,observerConfig)};var stop=function stop(){observer&&observer.disconnect()};return{start:start,stop:stop,localize:_localize.default}}();var _default=pseudoLocalization;exports.default=_default;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"localize",{enumerable:true,get:function get(){return _localize.default}});exports.default=void 0;var _localize=_interopRequireDefault(require("./localize.js"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var pseudoLocalization=function(){var opts={blacklistedNodeNames:["STYLE"]};var isEnabled=false;var observer=null;var observerConfig={characterData:true,childList:true,subtree:true};var textNodesUnder=function textNodesUnder(element){var walker=document.createTreeWalker(element,NodeFilter.SHOW_TEXT,function(node){var isAllWhitespace=!/[^\s]/.test(node.nodeValue);if(isAllWhitespace)return NodeFilter.FILTER_REJECT;var isBlacklistedNode=opts.blacklistedNodeNames.includes(node.parentElement.nodeName);if(isBlacklistedNode)return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT});var currNode;var textNodes=[];while(currNode=walker.nextNode()){textNodes.push(currNode)}return textNodes};var isNonEmptyString=function isNonEmptyString(str){return str&&typeof str==="string"};var pseudoLocalize=function pseudoLocalize(element){var textNodesUnderElement=textNodesUnder(element);var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=textNodesUnderElement[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var textNode=_step.value;var nodeValue=textNode.nodeValue;if(isNonEmptyString(nodeValue)){textNode.nodeValue=(0,_localize.default)(nodeValue,opts)}}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator.return!=null){_iterator.return()}}finally{if(_didIteratorError){throw _iteratorError}}}};var domMutationCallback=function domMutationCallback(mutationsList){var _iteratorNormalCompletion2=true;var _didIteratorError2=false;var _iteratorError2=undefined;try{for(var _iterator2=mutationsList[Symbol.iterator](),_step2;!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=true){var mutation=_step2.value;if(mutation.type==="childList"&&mutation.addedNodes.length>0){observer.disconnect();mutation.addedNodes.forEach(pseudoLocalize);observer.observe(document.body,observerConfig)}else if(mutation.type==="characterData"){var nodeValue=mutation.target.nodeValue;var isBlacklistedNode=opts.blacklistedNodeNames.includes(mutation.target.parentElement.nodeName);if(isNonEmptyString(nodeValue)&&!isBlacklistedNode){observer.disconnect();mutation.target.nodeValue=(0,_localize.default)(nodeValue,opts);observer.observe(document.body,observerConfig)}}}}catch(err){_didIteratorError2=true;_iteratorError2=err}finally{try{if(!_iteratorNormalCompletion2&&_iterator2.return!=null){_iterator2.return()}}finally{if(_didIteratorError2){throw _iteratorError2}}}};var start=function start(){var _ref=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},_ref$strategy=_ref.strategy,strategy=_ref$strategy===void 0?"accented":_ref$strategy,_ref$blacklistedNodeN=_ref.blacklistedNodeNames,blacklistedNodeNames=_ref$blacklistedNodeN===void 0?opts.blacklistedNodeNames:_ref$blacklistedNodeN;opts.blacklistedNodeNames=blacklistedNodeNames;opts.strategy=strategy;pseudoLocalize(document.body);observer=new MutationObserver(domMutationCallback);observer.observe(document.body,observerConfig);isEnabled=true};var stop=function stop(){observer&&observer.disconnect();isEnabled=false};return{start:start,stop:stop,isEnabled:isEnabled,localize:_localize.default}}();var _default=pseudoLocalization;exports.default=_default;
2
2
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["pseudoLocalization","opts","blacklistedNodeNames","observer","observerConfig","characterData","childList","subtree","textNodesUnder","element","walker","document","createTreeWalker","NodeFilter","SHOW_TEXT","node","isAllWhitespace","test","nodeValue","FILTER_REJECT","isBlacklistedNode","includes","parentElement","nodeName","FILTER_ACCEPT","currNode","textNodes","nextNode","push","isNonEmptyString","str","pseudoLocalize","textNodesUnderElement","textNode","domMutationCallback","mutationsList","mutation","type","addedNodes","length","disconnect","forEach","observe","body","target","start","strategy","MutationObserver","stop","localize","pseudoLocalizeString"],"mappings":"sMAAA,+D,k7CASA,GAAMA,CAAAA,kBAAkB,CAAI,UAAM,CAChC,GAAMC,CAAAA,IAAI,CAAG,CACXC,oBAAoB,CAAE,CAAC,OAAD,CADX,CAAb,CAMA,GAAIC,CAAAA,QAAQ,CAAG,IAAf,CACA,GAAMC,CAAAA,cAAc,CAAG,CACrBC,aAAa,CAAE,IADM,CAErBC,SAAS,CAAE,IAFU,CAGrBC,OAAO,CAAE,IAHY,CAAvB,CAMA,GAAMC,CAAAA,cAAc,CAAG,QAAjBA,CAAAA,cAAiB,CAAAC,OAAO,CAAI,CAChC,GAAMC,CAAAA,MAAM,CAAGC,QAAQ,CAACC,gBAAT,CACbH,OADa,CAEbI,UAAU,CAACC,SAFE,CAGb,SAAAC,IAAI,CAAI,CACN,GAAMC,CAAAA,eAAe,CAAG,CAAC,QAAQC,IAAR,CAAaF,IAAI,CAACG,SAAlB,CAAzB,CACA,GAAIF,eAAJ,CAAqB,MAAOH,CAAAA,UAAU,CAACM,aAAlB,CAErB,GAAMC,CAAAA,iBAAiB,CAAGnB,IAAI,CAACC,oBAAL,CAA0BmB,QAA1B,CACxBN,IAAI,CAACO,aAAL,CAAmBC,QADK,CAA1B,CAGA,GAAIH,iBAAJ,CAAuB,MAAOP,CAAAA,UAAU,CAACM,aAAlB,CAEvB,MAAON,CAAAA,UAAU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String from './localize.js';\n\n/**\n * export the underlying pseudo localization function so this import style\n * import { localize } from 'pseudo-localization';\n * can be used.\n */\nexport { default as localize } from './localize.js';\n\nconst pseudoLocalization = (() => {\n const opts = {\n blacklistedNodeNames: ['STYLE'],\n };\n\n // Observer for dom updates. Initialization is defered to make parts\n // of the API safe to use in non-browser environments like nodejs\n let observer = null;\n const observerConfig = {\n characterData: true,\n childList: true,\n subtree: true,\n };\n\n const textNodesUnder = element => {\n const walker = document.createTreeWalker(\n element,\n NodeFilter.SHOW_TEXT,\n node => {\n const isAllWhitespace = !/[^\\s]/.test(node.nodeValue);\n if (isAllWhitespace) return NodeFilter.FILTER_REJECT;\n\n const isBlacklistedNode = opts.blacklistedNodeNames.includes(\n node.parentElement.nodeName\n );\n if (isBlacklistedNode) return NodeFilter.FILTER_REJECT;\n\n return NodeFilter.FILTER_ACCEPT;\n }\n );\n\n let currNode;\n const textNodes = [];\n while ((currNode = walker.nextNode())) textNodes.push(currNode);\n return textNodes;\n };\n\n const isNonEmptyString = str => str && typeof str === 'string';\n\n const pseudoLocalize = element => {\n const textNodesUnderElement = textNodesUnder(element);\n for (let textNode of textNodesUnderElement) {\n const nodeValue = textNode.nodeValue;\n if (isNonEmptyString(nodeValue)) {\n textNode.nodeValue = pseudoLocalizeString(nodeValue, opts);\n }\n }\n };\n\n const domMutationCallback = mutationsList => {\n for (let mutation of mutationsList) {\n if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {\n // Turn the observer off while performing dom manipulation to prevent\n // infinite dom mutation callback loops\n observer.disconnect();\n // For every node added, recurse down it's subtree and convert\n // all children as well\n mutation.addedNodes.forEach(pseudoLocalize);\n observer.observe(document.body, observerConfig);\n } else if (mutation.type === 'characterData') {\n const nodeValue = mutation.target.nodeValue;\n const isBlacklistedNode = opts.blacklistedNodeNames.includes(\n mutation.target.parentElement.nodeName\n );\n if (isNonEmptyString(nodeValue) && !isBlacklistedNode) {\n // Turn the observer off while performing dom manipulation to prevent\n // infinite dom mutation callback loops\n observer.disconnect();\n // The target will always be a text node so it can be converted\n // directly\n mutation.target.nodeValue = pseudoLocalizeString(nodeValue, opts);\n observer.observe(document.body, observerConfig);\n }\n }\n }\n };\n\n const start = ({\n strategy = 'accented',\n blacklistedNodeNames = opts.blacklistedNodeNames,\n } = {}) => {\n opts.blacklistedNodeNames = blacklistedNodeNames;\n opts.strategy = strategy;\n // Pseudo localize the DOM\n pseudoLocalize(document.body);\n // Start observing the DOM for changes and run\n // pseudo localization on any added text nodes\n observer = new MutationObserver(domMutationCallback);\n observer.observe(document.body, observerConfig);\n };\n\n const stop = () => {\n observer && observer.disconnect();\n };\n\n return {\n start,\n stop,\n localize: pseudoLocalizeString,\n };\n})();\n\nexport default pseudoLocalization;\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["pseudoLocalization","opts","blacklistedNodeNames","isEnabled","observer","observerConfig","characterData","childList","subtree","textNodesUnder","element","walker","document","createTreeWalker","NodeFilter","SHOW_TEXT","node","isAllWhitespace","test","nodeValue","FILTER_REJECT","isBlacklistedNode","includes","parentElement","nodeName","FILTER_ACCEPT","currNode","textNodes","nextNode","push","isNonEmptyString","str","pseudoLocalize","textNodesUnderElement","textNode","domMutationCallback","mutationsList","mutation","type","addedNodes","length","disconnect","forEach","observe","body","target","start","strategy","MutationObserver","stop","localize","pseudoLocalizeString"],"mappings":"sMAAA,+D,kFASA,GAAMA,CAAAA,kBAAkB,CAAI,UAAM,CAChC,GAAMC,CAAAA,IAAI,CAAG,CACXC,oBAAoB,CAAE,CAAC,OAAD,CADX,CAAb,CAKA,GAAIC,CAAAA,SAAS,CAAG,KAAhB,CAIA,GAAIC,CAAAA,QAAQ,CAAG,IAAf,CACA,GAAMC,CAAAA,cAAc,CAAG,CACrBC,aAAa,CAAE,IADM,CAErBC,SAAS,CAAE,IAFU,CAGrBC,OAAO,CAAE,IAHY,CAAvB,CAMA,GAAMC,CAAAA,cAAc,CAAG,QAAjBA,CAAAA,cAAiB,CAAAC,OA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L,CAAgBA,QAAhB,CAEAf,cAAc,CAACpB,QAAQ,CAACgC,IAAV,CAAd,CAGAxC,QAAQ,CAAG,GAAI4C,CAAAA,gBAAJ,CAAqBb,mBAArB,CAAX,CACA/B,QAAQ,CAACuC,OAAT,CAAiB/B,QAAQ,CAACgC,IAA1B,CAAgCvC,cAAhC,EACAF,SAAS,CAAG,IACb,CAbD,CAeA,GAAM8C,CAAAA,IAAI,CAAG,QAAPA,CAAAA,IAAO,EAAM,CACjB7C,QAAQ,EAAIA,QAAQ,CAACqC,UAAT,EAAZ,CACAtC,SAAS,CAAG,KACb,CAHD,CAKA,MAAO,CACL2C,KAAK,CAALA,KADK,CAELG,IAAI,CAAJA,IAFK,CAGL9C,SAAS,CAATA,SAHK,CAIL+C,QAAQ,CAAEC,iBAJL,CAMR,CA1G0B,EAA3B,C,aA4GenD,kB","sourcesContent":["import pseudoLocalizeString from './localize.js';\n\n/**\n * export the underlying pseudo localization function so this import style\n * import { localize } from 'pseudo-localization';\n * can be used.\n */\nexport { default as localize } from './localize.js';\n\nconst pseudoLocalization = (() => {\n const opts = {\n blacklistedNodeNames: ['STYLE'],\n };\n\n // Indicates whether the pseudo-localization is currently enabled.\n let isEnabled = false;\n\n // Observer for dom updates. Initialization is defered to make parts\n // of the API safe to use in non-browser environments like nodejs\n let observer = null;\n const observerConfig = {\n characterData: true,\n childList: true,\n subtree: true,\n };\n\n const textNodesUnder = element => {\n const walker = document.createTreeWalker(\n element,\n NodeFilter.SHOW_TEXT,\n node => {\n const isAllWhitespace = !/[^\\s]/.test(node.nodeValue);\n if (isAllWhitespace) return NodeFilter.FILTER_REJECT;\n\n const isBlacklistedNode = opts.blacklistedNodeNames.includes(\n node.parentElement.nodeName\n );\n if (isBlacklistedNode) return NodeFilter.FILTER_REJECT;\n\n return NodeFilter.FILTER_ACCEPT;\n }\n );\n\n let currNode;\n const textNodes = [];\n while ((currNode = walker.nextNode())) textNodes.push(currNode);\n return textNodes;\n };\n\n const isNonEmptyString = str => str && typeof str === 'string';\n\n const pseudoLocalize = element => {\n const textNodesUnderElement = textNodesUnder(element);\n for (let textNode of textNodesUnderElement) {\n const nodeValue = textNode.nodeValue;\n if (isNonEmptyString(nodeValue)) {\n textNode.nodeValue = pseudoLocalizeString(nodeValue, opts);\n }\n }\n };\n\n const domMutationCallback = mutationsList => {\n for (let mutation of mutationsList) {\n if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {\n // Turn the observer off while performing dom manipulation to prevent\n // infinite dom mutation callback loops\n observer.disconnect();\n // For every node added, recurse down it's subtree and convert\n // all children as well\n mutation.addedNodes.forEach(pseudoLocalize);\n observer.observe(document.body, observerConfig);\n } else if (mutation.type === 'characterData') {\n const nodeValue = mutation.target.nodeValue;\n const isBlacklistedNode = opts.blacklistedNodeNames.includes(\n mutation.target.parentElement.nodeName\n );\n if (isNonEmptyString(nodeValue) && !isBlacklistedNode) {\n // Turn the observer off while performing dom manipulation to prevent\n // infinite dom mutation callback loops\n observer.disconnect();\n // The target will always be a text node so it can be converted\n // directly\n mutation.target.nodeValue = pseudoLocalizeString(nodeValue, opts);\n observer.observe(document.body, observerConfig);\n }\n }\n }\n };\n\n const start = ({\n strategy = 'accented',\n blacklistedNodeNames = opts.blacklistedNodeNames,\n } = {}) => {\n opts.blacklistedNodeNames = blacklistedNodeNames;\n opts.strategy = strategy;\n // Pseudo localize the DOM\n pseudoLocalize(document.body);\n // Start observing the DOM for changes and run\n // pseudo localization on any added text nodes\n observer = new MutationObserver(domMutationCallback);\n observer.observe(document.body, observerConfig);\n isEnabled = true;\n };\n\n const stop = () => {\n observer && observer.disconnect();\n isEnabled = false;\n };\n\n return {\n start,\n stop,\n isEnabled,\n localize: pseudoLocalizeString,\n };\n})();\n\nexport default pseudoLocalization;\n"],"file":"index.js"}
package/lib/localize.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;function _createForOfIteratorHelper(o,allowArrayLike){var it=typeof Symbol!=="undefined"&&o[Symbol.iterator]||o["@@iterator"];if(!it){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;var F=function F(){};return{s:F,n:function n(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]}},e:function e(_e){throw _e},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var normalCompletion=true,didErr=false,err;return{s:function s(){it=it.call(o)},n:function n(){var step=it.next();normalCompletion=step.done;return step},e:function e(_e2){didErr=true;err=_e2},f:function f(){try{if(!normalCompletion&&it.return!=null)it.return()}finally{if(didErr)throw err}}}}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i]}return arr2}var ACCENTED_MAP={a:"\u0227",A:"\u0226",b:"\u0180",B:"\u0181",c:"\u0188",C:"\u0187",d:"\u1E13",D:"\u1E12",e:"\u1E17",E:"\u1E16",f:"\u0192",F:"\u0191",g:"\u0260",G:"\u0193",h:"\u0127",H:"\u0126",i:"\u012B",I:"\u012A",j:"\u0135",J:"\u0134",k:"\u0137",K:"\u0136",l:"\u0140",L:"\u013F",m:"\u1E3F",M:"\u1E3E",n:"\u019E",N:"\u0220",o:"\u01FF",O:"\u01FE",p:"\u01A5",P:"\u01A4",q:"\u024B",Q:"\u024A",r:"\u0159",R:"\u0158",s:"\u015F",S:"\u015E",t:"\u0167",T:"\u0166",v:"\u1E7D",V:"\u1E7C",u:"\u016D",U:"\u016C",w:"\u1E87",W:"\u1E86",x:"\u1E8B",X:"\u1E8A",y:"\u1E8F",Y:"\u1E8E",z:"\u1E91",Z:"\u1E90"};var BIDI_MAP={a:"\u0250",A:"\u2200",b:"q",B:"\u0510",c:"\u0254",C:"\u2183",d:"p",D:"\u15E1",e:"\u01DD",E:"\u018E",f:"\u025F",F:"\u2132",g:"\u0183",G:"\u2141",h:"\u0265",H:"H",i:"\u0131",I:"I",j:"\u027E",J:"\u017F",k:"\u029E",K:"\u04FC",l:"\u0285",L:"\u2142",m:"\u026F",M:"W",n:"u",N:"N",o:"o",O:"O",p:"d",P:"\u0500",q:"b",Q:"\xD2",r:"\u0279",R:"\u1D1A",s:"s",S:"S",t:"\u0287",T:"\u22A5",u:"n",U:"\u2229",v:"\u028C",V:"\u0245",w:"\u028D",W:"M",x:"x",X:"X",y:"\u028E",Y:"\u2144",z:"z",Z:"Z"};var strategies={accented:{prefix:"",postfix:"",map:ACCENTED_MAP,elongate:true},bidi:{prefix:"\u202E",postfix:"\u202C",map:BIDI_MAP,elongate:false}};var pseudoLocalizeString=function pseudoLocalizeString(string){var _ref=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},_ref$strategy=_ref.strategy,strategy=_ref$strategy===void 0?"accented":_ref$strategy;var opts=strategies[strategy];var pseudoLocalizedText="";var _iterator=_createForOfIteratorHelper(string),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var character=_step.value;if(opts.map[character]){var cl=character.toLowerCase();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}}catch(err){_iterator.e(err)}finally{_iterator.f()}if(pseudoLocalizedText.startsWith(opts.prefix)&&pseudoLocalizedText.endsWith(opts.postfix)){return pseudoLocalizedText}return opts.prefix+pseudoLocalizedText+opts.postfix};var _default=pseudoLocalizeString;exports.default=_default;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var ACCENTED_MAP={a:"\u0227",A:"\u0226",b:"\u0180",B:"\u0181",c:"\u0188",C:"\u0187",d:"\u1E13",D:"\u1E12",e:"\u1E17",E:"\u1E16",f:"\u0192",F:"\u0191",g:"\u0260",G:"\u0193",h:"\u0127",H:"\u0126",i:"\u012B",I:"\u012A",j:"\u0135",J:"\u0134",k:"\u0137",K:"\u0136",l:"\u0140",L:"\u013F",m:"\u1E3F",M:"\u1E3E",n:"\u019E",N:"\u0220",o:"\u01FF",O:"\u01FE",p:"\u01A5",P:"\u01A4",q:"\u024B",Q:"\u024A",r:"\u0159",R:"\u0158",s:"\u015F",S:"\u015E",t:"\u0167",T:"\u0166",v:"\u1E7D",V:"\u1E7C",u:"\u016D",U:"\u016C",w:"\u1E87",W:"\u1E86",x:"\u1E8B",X:"\u1E8A",y:"\u1E8F",Y:"\u1E8E",z:"\u1E91",Z:"\u1E90"};var BIDI_MAP={a:"\u0250",A:"\u2200",b:"q",B:"\u0510",c:"\u0254",C:"\u2183",d:"p",D:"\u15E1",e:"\u01DD",E:"\u018E",f:"\u025F",F:"\u2132",g:"\u0183",G:"\u2141",h:"\u0265",H:"H",i:"\u0131",I:"I",j:"\u027E",J:"\u017F",k:"\u029E",K:"\u04FC",l:"\u0285",L:"\u2142",m:"\u026F",M:"W",n:"u",N:"N",o:"o",O:"O",p:"d",P:"\u0500",q:"b",Q:"\xD2",r:"\u0279",R:"\u1D1A",s:"s",S:"S",t:"\u0287",T:"\u22A5",u:"n",U:"\u2229",v:"\u028C",V:"\u0245",w:"\u028D",W:"M",x:"x",X:"X",y:"\u028E",Y:"\u2144",z:"z",Z:"Z"};var strategies={accented:{prefix:"",postfix:"",map:ACCENTED_MAP,elongate:true},bidi:{prefix:"\u202E",postfix:"\u202C",map:BIDI_MAP,elongate:false}};var pseudoLocalizeString=function pseudoLocalizeString(string){var _ref=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},_ref$strategy=_ref.strategy,strategy=_ref$strategy===void 0?"accented":_ref$strategy;var opts=strategies[strategy];var pseudoLocalizedText="";var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=string[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var character=_step.value;if(opts.map[character]){var cl=character.toLowerCase();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}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator.return!=null){_iterator.return()}}finally{if(_didIteratorError){throw _iteratorError}}}if(pseudoLocalizedText.startsWith(opts.prefix)&&pseudoLocalizedText.endsWith(opts.postfix)){return pseudoLocalizedText}return opts.prefix+pseudoLocalizedText+opts.postfix};var _default=pseudoLocalizeString;exports.default=_default;
2
2
  //# sourceMappingURL=localize.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/localize.js"],"names":["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","BIDI_MAP","strategies","accented","prefix","postfix","map","elongate","bidi","pseudoLocalizeString","string","strategy","opts","pseudoLocalizedText","character","cl","toLowerCase","startsWith","endsWith"],"mappings":"67CAAA,GAAMA,CAAAA,YAAY,CAAG,CACnBC,CAAC,CAAE,QADgB,CAEnBC,CAAC,CAAE,QAFgB,CAGnBC,CAAC,CAAE,QAHgB,CAInBC,CAAC,CAAE,QAJgB,CAKnBC,CAAC,CAAE,QALgB,CAMnBC,CAAC,CAAE,QANgB,CAOnBC,CAAC,CAAE,QAPgB,CAQnBC,CAAC,CAAE,QARgB,CASnBC,CAAC,CAAE,QATgB,CAUnBC,CAAC,CAAE,QAVgB,CAWnBC,CAAC,CAAE,Q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 'ɥ',\n H: 'H',\n i: 'ı',\n I: 'I',\n j: 'ɾ',\n J: 'ſ',\n k: 'ʞ',\n K: 'Ӽ',\n l: 'ʅ',\n L: '⅂',\n m: 'ɯ',\n M: 'W',\n n: 'u',\n N: 'N',\n o: 'o',\n O: 'O',\n p: 'd',\n P: 'Ԁ',\n q: 'b',\n Q: 'Ò',\n r: 'ɹ',\n R: 'ᴚ',\n s: 's',\n S: 'S',\n t: 'ʇ',\n T: '⊥',\n u: 'n',\n U: '∩',\n v: 'ʌ',\n V: 'Ʌ',\n w: 'ʍ',\n W: 'M',\n x: 'x',\n X: 'X',\n y: 'ʎ',\n Y: '⅄',\n z: 'z',\n Z: 'Z',\n};\n\nconst strategies = {\n accented: {\n prefix: '',\n postfix: '',\n map: ACCENTED_MAP,\n elongate: true,\n },\n bidi: {\n // Surround words with Unicode formatting marks forcing\n // right-to-left directionality of characters\n prefix: '\\u202e',\n postfix: '\\u202c',\n map: BIDI_MAP,\n elongate: false,\n },\n};\n\nconst pseudoLocalizeString = (string, { strategy = 'accented' } = {}) => {\n let opts = strategies[strategy];\n\n let pseudoLocalizedText = '';\n for (let character of string) {\n if (opts.map[character]) {\n const cl = character.toLowerCase();\n // duplicate \"a\", \"e\", \"o\" and \"u\" to emulate ~30% longer text\n if (\n opts.elongate &&\n (cl === 'a' || cl === 'e' || cl === 'o' || cl === 'u')\n ) {\n pseudoLocalizedText += opts.map[character] + opts.map[character];\n } else pseudoLocalizedText += opts.map[character];\n } else pseudoLocalizedText += character;\n }\n\n // If this string is from the DOM, it should already contain the pre- and postfix\n if (\n pseudoLocalizedText.startsWith(opts.prefix) &&\n pseudoLocalizedText.endsWith(opts.postfix)\n ) {\n return pseudoLocalizedText;\n }\n return opts.prefix + pseudoLocalizedText + opts.postfix;\n};\n\nexport default pseudoLocalizeString;\n"],"file":"localize.js"}
1
+ {"version":3,"sources":["../src/localize.js"],"names":["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","BIDI_MAP","strategies","accented","prefix","postfix","map","elongate","bidi","pseudoLocalizeString","string","strategy","opts","pseudoLocalizedText","character","cl","toLowerCase","startsWith","endsWith"],"mappings":"6FAAA,GAAMA,CAAAA,YAAY,CAAG,CACnBC,CAAC,CAAE,QADgB,CAEnBC,CAAC,CAAE,QAFgB,CAGnBC,CAAC,CAAE,QAHgB,CAInBC,CAAC,CAAE,QAJgB,CAKnBC,CAAC,CAAE,QALgB,CAMnBC,CAAC,CAAE,QANgB,CAOnBC,CAAC,CAAE,QAPgB,CAQnBC,CAAC,CAAE,QARgB,CASnBC,CAAC,CAAE,QATgB,CAUnBC,CAAC,CAAE,QAVgB,CAWnBC,CAAC,CAAE,QAXgB,CAYnBC,CAAC,CAAE,QAZgB,CAanBC,CAAC,CAAE,QAbgB,CAcnBC,CAAC,CAAE,QAdgB,CAenBC,CAAC,CAAE,QAfgB,CAgBnBC,CAAC,CAAE,QAhBgB,CAiBnBC,CAAC,CAAE,QAjBgB,CAkBnBC,CAAC,CAAE,QAlBgB,CAmBnBC,CAAC,CAAE,QAnBgB,CAoBnBC,CAAC,CAAE,QApBgB,CAqBnBC,CAAC,CAAE,QArBgB,CAsBnBC,CAAC,CAAE,QAtBgB,CAuBnBC,CAAC,CAAE,QAvBgB,CAwBnBC,CAAC,CAAE,QAxBgB,CAyBnBC,CAAC,CAAE,QAzBgB,CA0BnBC,CAAC,CAAE,QA1BgB,CA2BnBC,CAAC,CAAE,QA3BgB,CA4BnBC,CAAC,CAAE,QA5BgB,CA6BnBC,CAAC,CAAE,QA7BgB,CA8BnBC,CAAC,CAAE,QA9BgB,CA+BnBC,CAAC,CAAE,QA/BgB,CAgCnBC,CAAC,CAAE,QAhCgB,CAiCnBC,CAAC,CAAE,QAjCgB,CAkCnBC,CAAC,CAAE,QAlCgB,CAmCnBC,CAAC,CAAE,QA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ǿ',\n O: 'Ǿ',\n p: 'ƥ',\n P: 'Ƥ',\n q: 'ɋ',\n Q: 'Ɋ',\n r: 'ř',\n R: 'Ř',\n s: 'ş',\n S: 'Ş',\n t: 'ŧ',\n T: 'Ŧ',\n v: 'ṽ',\n V: 'Ṽ',\n u: 'ŭ',\n U: 'Ŭ',\n w: 'ẇ',\n W: 'Ẇ',\n x: 'ẋ',\n X: 'Ẋ',\n y: 'ẏ',\n Y: 'Ẏ',\n z: 'ẑ',\n Z: 'Ẑ',\n};\n\nconst BIDI_MAP = {\n a: 'ɐ',\n A: '∀',\n b: 'q',\n B: 'Ԑ',\n c: 'ɔ',\n C: 'Ↄ',\n d: 'p',\n D: 'ᗡ',\n e: 'ǝ',\n E: 'Ǝ',\n f: 'ɟ',\n F: 'Ⅎ',\n g: 'ƃ',\n G: '⅁',\n h: 'ɥ',\n H: 'H',\n i: 'ı',\n I: 'I',\n j: 'ɾ',\n J: 'ſ',\n k: 'ʞ',\n K: 'Ӽ',\n l: 'ʅ',\n L: '⅂',\n m: 'ɯ',\n M: 'W',\n n: 'u',\n N: 'N',\n o: 'o',\n O: 'O',\n p: 'd',\n P: 'Ԁ',\n q: 'b',\n Q: 'Ò',\n r: 'ɹ',\n R: 'ᴚ',\n s: 's',\n S: 'S',\n t: 'ʇ',\n T: '⊥',\n u: 'n',\n U: '∩',\n v: 'ʌ',\n V: 'Ʌ',\n w: 'ʍ',\n W: 'M',\n x: 'x',\n X: 'X',\n y: 'ʎ',\n Y: '⅄',\n z: 'z',\n Z: 'Z',\n};\n\nconst strategies = {\n accented: {\n prefix: '',\n postfix: '',\n map: ACCENTED_MAP,\n elongate: true,\n },\n bidi: {\n // Surround words with Unicode formatting marks forcing\n // right-to-left directionality of characters\n prefix: '\\u202e',\n postfix: '\\u202c',\n map: BIDI_MAP,\n elongate: false,\n },\n};\n\nconst pseudoLocalizeString = (string, { strategy = 'accented' } = {}) => {\n let opts = strategies[strategy];\n\n let pseudoLocalizedText = '';\n for (let character of string) {\n if (opts.map[character]) {\n const cl = character.toLowerCase();\n // duplicate \"a\", \"e\", \"o\" and \"u\" to emulate ~30% longer text\n if (\n opts.elongate &&\n (cl === 'a' || cl === 'e' || cl === 'o' || cl === 'u')\n ) {\n pseudoLocalizedText += opts.map[character] + opts.map[character];\n } else pseudoLocalizedText += opts.map[character];\n } else pseudoLocalizedText += character;\n }\n\n // If this string is from the DOM, it should already contain the pre- and postfix\n if (\n pseudoLocalizedText.startsWith(opts.prefix) &&\n pseudoLocalizedText.endsWith(opts.postfix)\n ) {\n return pseudoLocalizedText;\n }\n return opts.prefix + pseudoLocalizedText + opts.postfix;\n};\n\nexport default pseudoLocalizeString;\n"],"file":"localize.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pseudo-localization",
3
- "version": "2.2.2",
3
+ "version": "2.3.2",
4
4
  "description": "Dynamic pseudo-localization in the browser and nodejs",
5
5
  "main": "lib/index.js",
6
6
  "files": [
package/lib/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { pseudoLocalizeString, Options } from './localize';
2
- /**
3
- * export the underlying pseudo localization function so this import style
4
- * import { localize } from 'pseudo-localization';
5
- * can be used.
6
- */
7
- export { pseudoLocalizeString as localize };
8
- declare type StartOptions = Options & {
9
- blacklistedNodeNames?: string[];
10
- };
11
- declare const pseudoLocalization: {
12
- start: ({ strategy, blacklistedNodeNames, }?: StartOptions) => void;
13
- stop: () => void;
14
- localize: (string: string, { strategy }?: Options) => string;
15
- };
16
- export default pseudoLocalization;
package/lib/localize.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export declare type Strategy = 'accented' | 'bidi';
2
- export declare type Options = {
3
- strategy?: Strategy;
4
- };
5
- export declare const pseudoLocalizeString: (string: string, { strategy }?: Options) => string;
@@ -1,2 +0,0 @@
1
- "use strict";var _localize=_interopRequireDefault(require("./localize"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}describe("localize",function(){test("accented",function(){expect((0,_localize.default)("abcd")).toBe("\u0227\u0227\u0180\u0188\u1E13");expect((0,_localize.default)("aeou")).toBe("\u0227\u0227\u1E17\u1E17\u01FF\u01FF\u016D\u016D");expect((0,_localize.default)("foo bar")).toBe("\u0192\u01FF\u01FF\u01FF\u01FF \u0180\u0227\u0227\u0159");expect((0,_localize.default)("CAPITAL_LETTERS")).toBe("\u0187\u0226\u0226\u01A4\u012A\u0166\u0226\u0226\u013F_\u013F\u1E16\u1E16\u0166\u0166\u1E16\u1E16\u0158\u015E");expect((0,_localize.default)("123,. n -~\xF0\xDE")).toBe("123,. \u019E -~\xF0\xDE")});test("bidi",function(){var bidi={strategy:"bidi"};expect((0,_localize.default)("abcd",bidi)).toBe("\u202E\u0250q\u0254p\u202C");expect((0,_localize.default)("aeou",bidi)).toBe("\u202E\u0250\u01DDon\u202C");expect((0,_localize.default)("foo bar",bidi)).toBe("\u202E\u025Foo q\u0250\u0279\u202C");expect((0,_localize.default)("CAPITAL_LETTERS",bidi)).toBe("\u202E\u2183\u2200\u0500I\u22A5\u2200\u2142_\u2142\u018E\u22A5\u22A5\u018E\u1D1AS\u202C");expect((0,_localize.default)("123,. n -~\xF0\xDE",bidi)).toBe("\u202E123,. u -~\xF0\xDE\u202C");expect((0,_localize.default)("\u202E\u025Foo\u202C",bidi)).toBe("\u202E\u025Foo\u202C")})});
2
- //# sourceMappingURL=localize.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/localize.test.js"],"names":["describe","test","expect","toBe","bidi","strategy"],"mappings":"aAAA,4D,kFAEAA,QAAQ,CAAC,UAAD,CAAa,UAAM,CACzBC,IAAI,CAAC,UAAD,CAAa,UAAM,CACrBC,MAAM,CAAC,sBAAS,MAAT,CAAD,CAAN,CAAyBC,IAAzB,CAA8B,gCAA9B,EAEAD,MAAM,CAAC,sBAAS,MAAT,CAAD,CAAN,CAAyBC,IAAzB,CAA8B,kDAA9B,EACAD,MAAM,CAAC,sBAAS,SAAT,CAAD,CAAN,CAA4BC,IAA5B,CAAiC,yDAAjC,EACAD,MAAM,CAAC,sBAAS,iBAAT,CAAD,CAAN,CAAoCC,IAApC,CAAyC,+GAAzC,EAEAD,MAAM,CAAC,sBAAS,oBAAT,CAAD,CAAN,CAAiCC,IAAjC,CAAsC,yBAAtC,CACD,CARG,CAAJ,CAUAF,IAAI,CAAC,MAAD,CAAS,UAAM,CACjB,GAAMG,CAAAA,IAAI,CAAG,CAAEC,QAAQ,CAAE,MAAZ,CAAb,CAYAH,MAAM,CAAC,sBAAS,MAAT,CAAiBE,IAAjB,CAAD,CAAN,CAA+BD,IAA/B,CAAoC,4BAApC,EACAD,MAAM,CAAC,sBAAS,MAAT,CAAiBE,IAAjB,CAAD,CAAN,CAA+BD,IAA/B,CAAoC,4BAApC,EACAD,MAAM,CAAC,sBAAS,SAAT,CAAoBE,IAApB,CAAD,CAAN,CAAkCD,IAAlC,CAAuC,oCAAvC,EACAD,MAAM,CAAC,sBAAS,iBAAT,CAA4BE,IAA5B,CAAD,CAAN,CAA0CD,IAA1C,CAA+C,yFAA/C,EACAD,MAAM,CAAC,sBAAS,oBAAT,CAAyBE,IAAzB,CAAD,CAAN,CAAuCD,IAAvC,CAA4C,gCAA5C,EAEAD,MAAM,CAAC,sBAAS,sBAAT,CAAkBE,IAAlB,CAAD,CAAN,CAAgCD,IAAhC,CAAqC,sBAArC,CACD,CApBG,CAqBL,CAhCO,CAAR","sourcesContent":["import localize from './localize';\n\ndescribe('localize', () => {\n test('accented', () => {\n expect(localize('abcd')).toBe('ȧȧƀƈḓ');\n // aeou are duplicated\n expect(localize('aeou')).toBe('ȧȧḗḗǿǿŭŭ');\n expect(localize('foo bar')).toBe('ƒǿǿǿǿ ƀȧȧř');\n expect(localize('CAPITAL_LETTERS')).toBe('ƇȦȦƤĪŦȦȦĿ_ĿḖḖŦŦḖḖŘŞ');\n // Everything except ASCII alphabet is passed through\n expect(localize('123,. n -~ðÞ')).toBe('123,. ƞ -~ðÞ');\n });\n\n test('bidi', () => {\n const bidi = { strategy: 'bidi' };\n\n /**\n * There are invisivle unicode formatting marks\n * surrounding each output. For example\n *\n * \"‮ɐqɔp‬\" is actually \"\\u202e\" + \"ɐqɔp\" + \"\\u202c\"\n *\n * The presense of the formatting marks cause most UIs\n * (likely including your text editor) to render the\n * string backwards, if you will, or from right-to-left.\n */\n expect(localize('abcd', bidi)).toBe('‮ɐqɔp‬');\n expect(localize('aeou', bidi)).toBe('‮ɐǝon‬');\n expect(localize('foo bar', bidi)).toBe('‮ɟoo qɐɹ‬');\n expect(localize('CAPITAL_LETTERS', bidi)).toBe('‮Ↄ∀ԀI⊥∀⅂_⅂Ǝ⊥⊥ƎᴚS‬');\n expect(localize('123,. n -~ðÞ', bidi)).toBe('‮123,. u -~ðÞ‬');\n // formatting marks are not duplicated if already present\n expect(localize('‮ɟoo‬', bidi)).toBe('‮ɟoo‬');\n });\n});\n"],"file":"localize.test.js"}