UNPKG

g1lib

Version:

An ubiquitous static javascript toolbox lib for Ǧ1 / Duniter ecosystem with reliability in mind.

4 lines (3 loc) 23.1 kB
const w={"(":String.fromCharCode(8960),")":String.fromCharCode(8961),"|":String.fromCharCode(8962),"{":String.fromCharCode(8963),"}":String.fromCharCode(8964),",":String.fromCharCode(8965),"[":String.fromCharCode(8966),"]":String.fromCharCode(8967),"-":String.fromCharCode(8968),"<":String.fromCharCode(8969),">":String.fromCharCode(8970),":":String.fromCharCode(8971),"=":String.fromCharCode(8972),"@":String.fromCharCode(8973),"\\":String.fromCharCode(8974)},L=ne(w);function ne(e){const n={};for(const t in e)n[e[t]]=t;return n}function Y(e){return e.replace(/\\(.)/g,(n,t)=>w[t]?w[t]:t)}function O(e){return e.split("").map(n=>L[n]?L[n]:n).join("")}function C(e){return e.split("").map(n=>L[n]?`\\${L[n]}`:n).join("")}function P(e){return e.replace(/./g,n=>w[n]?w[n]:n)}function h(e){const n=Y(e).split(""),t=J(n);if(n.length)throw new Error(`fail to build tree from : "${C(e)}" parsed: ${JSON.stringify(t)} unparsed/failed: ${C(n.join(""))}`);let i,r=t;do i=JSON.stringify(r),r=K(r);while(JSON.stringify(r)!==i);return N(r),r}function g(e){e.str.length&&e.tree.alt[e.tree.alt.length-1].step.push({str:e.str}),e.str=""}function Z(e,n){n.str+=e}function te(e){e.tree.alt.push({step:[]})}function ie(e){e.tree.alt[e.tree.alt.length-1].step.push(J(e.input))}function oe(){return!0}const k={")":(e,n)=>oe(g(n)),"|":(e,n)=>(g(n),te(n),void 0),"(":(e,n)=>(g(n),ie(n),void 0),default:(e,n)=>Z(e,n)};function J(e){const n={input:e,str:"",tree:{alt:[{step:[]}]}};for(;n.input.length;){const t=n.input.shift();if(typeof k[t]<"u"){if(k[t](t,n))return n.tree}else k.default(t,n)}return g(n),n.tree}function re(e){const n={input:e,str:"",tree:{alt:[{step:[]}]}};return e.forEach(t=>{A(t)?Z(t.str,n):(g(n),n.tree.alt[n.tree.alt.length-1].step.push(t))}),g(n),n.tree.alt[n.tree.alt.length-1].step}function K(e){if(A(e))return e;const n=u(e)?"alt":"step";if(e[n]=e[n].map(K),e[n].length===0)return{str:""};if(e[n].length===1)return e[n][0];if(u(e))return e.alt=ae(e.alt),e.alt=[].concat(...e.alt.map(t=>u(t)?t.alt:[t])),e;if(y(e))return e.step=re(e.step),e}function A(e){return typeof e=="object"&&typeof e.str=="string"}function y(e){return typeof e=="object"&&typeof e.step<"u"}function u(e){return typeof e=="object"&&typeof e.alt<"u"}function ae(e){const n={};return e.forEach(t=>n[JSON.stringify(t)]=t),Object.keys(n).sort().map(JSON.parse)}function ce(e,n){function t(i){if(A(i)){if(!i.str.includes(e))return{notMatching:i.str};if(i.str.split(e).length>2)throw new Error("Error: @@ can only appear once in expression (idSec at left, password \xE0 right)");return{matching:i.str}}if(y(i)){let r=0,a=!1,c="",s="";if(i.step.forEach(E=>{const f=t(E);f.matching?(r++,typeof f.notMatching<"u"&&(a=!0),c+=f.matching,s+=f.notMatching):(c+=f.notMatching,s+=f.notMatching)}),r>1)throw new Error("Error: @@ can only appear once in expression (idSec at left, password \xE0 right)");return r&&a?{matching:c,notMatching:s}:r?{matching:c}:{notMatching:c}}if(u(i)){const r=[],a=[];if(i.alt.forEach(c=>{const s=t(c);typeof s.matching<"u"&&r.push(s.matching),typeof s.notMatching<"u"&&a.push(s.notMatching)}),r.length&&a.length)return{matching:`(${r.join("|")})`,notMatching:`(${a.join("|")})`};if(r.length)return{matching:`(${r.join("|")})`};if(a.length)return{notMatching:`(${a.join("|")})`}}throw new Error(`Error: how to splitAround ${e} with ${JSON.stringify(i)}`)}const o=t(n);return typeof o.matching<"u"&&(o.matching=m(h(o.matching))),typeof o.notMatching<"u"&&(o.notMatching=m(h(o.notMatching))),o}function M(e){return C(m(e))}function m(e){if(A(e))return e.str;if(y(e))return e.step.map(m).join("");if(u(e))return`(${e.alt.map(m).join("|")})`;throw new Error(`Error: how to serialize ${JSON.stringify(e)} RAW: ${e}`)}function N(e){if(A(e))return e.altCount=1,e.indexCost=1,1;if(u(e))return e.altCount=e.alt.reduce((n,t)=>n+N(t),0),e.indexCost=e.altCount-1,e.altCount;if(y(e)){e.altCount=e.step.reduce((t,o)=>t*N(o),1);let n=1;for(let t=e.step.length-1;t>=0;t--){const o=e.step[t];u(o)&&(o.alt.forEach(i=>R(i,n)),n*=o.altCount)}return e.indexCost=e.altCount,e.altCount}}function R(e,n){e.indexCost*=n,y(e)&&e.step.forEach(t=>R(t,n)),u(e)&&e.alt.forEach(t=>R(t,n))}function D(e){return e.altCount}function se(e,n){return O(j({index:e},n))}function v(e,n){return j({index:e},n)}function j(e,n){if(A(n))return n.str;if(y(n))return n.step.map(t=>j(e,t)).join("");if(u(n))for(const t of n.alt){if(e.index<t.indexCost)return j(e,t);e.index-=t.indexCost}throw new Error(`index out of bound : ${e.index+D(n)} asked, 0-${D(n)-1} available in ${M(n)}`)}function G(e){return typeof e=="string"?e.replace(/[^A-Za-z0-9]/g,function(n){return G.characters[n]||n}):e}G.characters={\u00C1:"A",\u0102:"A",\u1EAE:"A",\u1EB6:"A",\u1EB0:"A",\u1EB2:"A",\u1EB4:"A",\u01CD:"A",\u00C2:"A",\u1EA4:"A",\u1EAC:"A",\u1EA6:"A",\u1EA8:"A",\u1EAA:"A",\u00C4:"A",\u01DE:"A",\u0226:"A",\u01E0:"A",\u1EA0:"A",\u0200:"A",\u00C0:"A",\u1EA2:"A",\u0202:"A",\u0100:"A",\u0104:"A",\u00C5:"A",\u01FA:"A",\u1E00:"A","\u023A":"A",\u00C3:"A","\uA732":"AA",\u00C6:"AE",\u01FC:"AE",\u01E2:"AE","\uA734":"AO","\uA736":"AU","\uA738":"AV","\uA73A":"AV","\uA73C":"AY",\u1E02:"B",\u1E04:"B",\u0181:"B",\u1E06:"B","\u0243":"B",\u0182:"B",\u0106:"C",\u010C:"C",\u00C7:"C",\u1E08:"C",\u0108:"C",\u010A:"C",\u0187:"C","\u023B":"C",\u010E:"D",\u1E10:"D",\u1E12:"D",\u1E0A:"D",\u1E0C:"D",\u018A:"D",\u1E0E:"D",\u01F2:"D",\u01C5:"D",\u0110:"D",\u00D0:"D",\u018B:"D",\u01F1:"DZ",\u01C4:"DZ",\u00C9:"E",\u0114:"E",\u011A:"E",\u0228:"E",\u1E1C:"E",\u00CA:"E",\u1EBE:"E",\u1EC6:"E",\u1EC0:"E",\u1EC2:"E",\u1EC4:"E",\u1E18:"E",\u00CB:"E",\u0116:"E",\u1EB8:"E",\u0204:"E",\u00C8:"E",\u1EBA:"E",\u0206:"E",\u0112:"E",\u1E16:"E",\u1E14:"E",\u0118:"E","\u0246":"E",\u1EBC:"E",\u1E1A:"E","\uA76A":"ET",\u1E1E:"F",\u0191:"F",\u01F4:"G",\u011E:"G",\u01E6:"G",\u0122:"G",\u011C:"G",\u0120:"G",\u0193:"G",\u1E20:"G",\u01E4:"G",\u1E2A:"H",\u021E:"H",\u1E28:"H",\u0124:"H","\u2C67":"H",\u1E26:"H",\u1E22:"H",\u1E24:"H",\u0126:"H",\u00CD:"I",\u012C:"I",\u01CF:"I",\u00CE:"I",\u00CF:"I",\u1E2E:"I",\u0130:"I",\u1ECA:"I",\u0208:"I",\u00CC:"I",\u1EC8:"I",\u020A:"I",\u012A:"I",\u012E:"I",\u0197:"I",\u0128:"I",\u1E2C:"I","\uA779":"D","\uA77B":"F","\uA77D":"G","\uA782":"R","\uA784":"S","\uA786":"T","\uA76C":"IS",\u0134:"J","\u0248":"J",\u1E30:"K",\u01E8:"K",\u0136:"K","\u2C69":"K","\uA742":"K",\u1E32:"K",\u0198:"K",\u1E34:"K","\uA740":"K","\uA744":"K",\u0139:"L","\u023D":"L",\u013D:"L",\u013B:"L",\u1E3C:"L",\u1E36:"L",\u1E38:"L","\u2C60":"L","\uA748":"L",\u1E3A:"L",\u013F:"L","\u2C62":"L",\u01C8:"L",\u0141:"L",\u01C7:"LJ",\u1E3E:"M",\u1E40:"M",\u1E42:"M","\u2C6E":"M",\u0143:"N",\u0147:"N",\u0145:"N",\u1E4A:"N",\u1E44:"N",\u1E46:"N",\u01F8:"N",\u019D:"N",\u1E48:"N","\u0220":"N",\u01CB:"N",\u00D1:"N",\u01CA:"NJ",\u00D3:"O",\u014E:"O",\u01D1:"O",\u00D4:"O",\u1ED0:"O",\u1ED8:"O",\u1ED2:"O",\u1ED4:"O",\u1ED6:"O",\u00D6:"O",\u022A:"O",\u022E:"O",\u0230:"O",\u1ECC:"O",\u0150:"O",\u020C:"O",\u00D2:"O",\u1ECE:"O",\u01A0:"O",\u1EDA:"O",\u1EE2:"O",\u1EDC:"O",\u1EDE:"O",\u1EE0:"O",\u020E:"O","\uA74A":"O","\uA74C":"O",\u014C:"O",\u1E52:"O",\u1E50:"O",\u019F:"O",\u01EA:"O",\u01EC:"O",\u00D8:"O",\u01FE:"O",\u00D5:"O",\u1E4C:"O",\u1E4E:"O",\u022C:"O",\u01A2:"OI","\uA74E":"OO",\u0190:"E",\u0186:"O",\u0222:"OU",\u1E54:"P",\u1E56:"P","\uA752":"P",\u01A4:"P","\uA754":"P","\u2C63":"P","\uA750":"P","\uA758":"Q","\uA756":"Q",\u0154:"R",\u0158:"R",\u0156:"R",\u1E58:"R",\u1E5A:"R",\u1E5C:"R",\u0210:"R",\u0212:"R",\u1E5E:"R","\u024C":"R","\u2C64":"R","\uA73E":"C",\u018E:"E",\u015A:"S",\u1E64:"S",\u0160:"S",\u1E66:"S",\u015E:"S",\u015C:"S",\u0218:"S",\u1E60:"S",\u1E62:"S",\u1E68:"S",\u00DF:"ss",\u0164:"T",\u0162:"T",\u1E70:"T",\u021A:"T","\u023E":"T",\u1E6A:"T",\u1E6C:"T",\u01AC:"T",\u1E6E:"T",\u01AE:"T",\u0166:"T","\u2C6F":"A","\uA780":"L",\u019C:"M","\u0245":"V","\uA728":"TZ",\u00DA:"U",\u016C:"U",\u01D3:"U",\u00DB:"U",\u1E76:"U",\u00DC:"U",\u01D7:"U",\u01D9:"U",\u01DB:"U",\u01D5:"U",\u1E72:"U",\u1EE4:"U",\u0170:"U",\u0214:"U",\u00D9:"U",\u1EE6:"U",\u01AF:"U",\u1EE8:"U",\u1EF0:"U",\u1EEA:"U",\u1EEC:"U",\u1EEE:"U",\u0216:"U",\u016A:"U",\u1E7A:"U",\u0172:"U",\u016E:"U",\u0168:"U",\u1E78:"U",\u1E74:"U","\uA75E":"V",\u1E7E:"V",\u01B2:"V",\u1E7C:"V","\uA760":"VY",\u1E82:"W",\u0174:"W",\u1E84:"W",\u1E86:"W",\u1E88:"W",\u1E80:"W","\u2C72":"W",\u1E8C:"X",\u1E8A:"X",\u00DD:"Y",\u0176:"Y",\u0178:"Y",\u1E8E:"Y",\u1EF4:"Y",\u1EF2:"Y",\u01B3:"Y",\u1EF6:"Y","\u1EFE":"Y",\u0232:"Y","\u024E":"Y",\u1EF8:"Y",\u0179:"Z",\u017D:"Z",\u1E90:"Z","\u2C6B":"Z",\u017B:"Z",\u1E92:"Z",\u0224:"Z",\u1E94:"Z",\u01B5:"Z",\u00DE:"TH",\u0132:"IJ",\u0152:"OE","\u1D00":"A","\u1D01":"AE",\u0299:"B","\u1D03":"B","\u1D04":"C","\u1D05":"D","\u1D07":"E","\uA730":"F",\u0262:"G",\u029B:"G",\u029C:"H",\u026A:"I",\u0281:"R","\u1D0A":"J","\u1D0B":"K",\u029F:"L","\u1D0C":"L","\u1D0D":"M",\u0274:"N","\u1D0F":"O",\u0276:"OE","\u1D10":"O","\u1D15":"OU","\u1D18":"P",\u0280:"R","\u1D0E":"N","\u1D19":"R","\uA731":"S","\u1D1B":"T","\u2C7B":"E","\u1D1A":"R","\u1D1C":"U","\u1D20":"V","\u1D21":"W",\u028F:"Y","\u1D22":"Z",\u00E1:"a",\u0103:"a",\u1EAF:"a",\u1EB7:"a",\u1EB1:"a",\u1EB3:"a",\u1EB5:"a",\u01CE:"a",\u00E2:"a",\u1EA5:"a",\u1EAD:"a",\u1EA7:"a",\u1EA9:"a",\u1EAB:"a",\u00E4:"a",\u01DF:"a",\u0227:"a",\u01E1:"a",\u1EA1:"a",\u0201:"a",\u00E0:"a",\u1EA3:"a",\u0203:"a",\u0101:"a",\u0105:"a","\u1D8F":"a",\u1E9A:"a",\u00E5:"a",\u01FB:"a",\u1E01:"a","\u2C65":"a",\u00E3:"a","\uA733":"aa",\u00E6:"ae",\u01FD:"ae",\u01E3:"ae","\uA735":"ao","\uA737":"au","\uA739":"av","\uA73B":"av","\uA73D":"ay",\u1E03:"b",\u1E05:"b",\u0253:"b",\u1E07:"b","\u1D6C":"b","\u1D80":"b",\u0180:"b",\u0183:"b",\u0275:"o",\u0107:"c",\u010D:"c",\u00E7:"c",\u1E09:"c",\u0109:"c",\u0255:"c",\u010B:"c",\u0188:"c","\u023C":"c",\u010F:"d",\u1E11:"d",\u1E13:"d","\u0221":"d",\u1E0B:"d",\u1E0D:"d",\u0257:"d","\u1D91":"d",\u1E0F:"d","\u1D6D":"d","\u1D81":"d",\u0111:"d",\u0256:"d",\u018C:"d",\u00F0:"d",\u0131:"i","\u0237":"j",\u025F:"j",\u0284:"j",\u01F3:"dz",\u01C6:"dz",\u00E9:"e",\u0115:"e",\u011B:"e",\u0229:"e",\u1E1D:"e",\u00EA:"e",\u1EBF:"e",\u1EC7:"e",\u1EC1:"e",\u1EC3:"e",\u1EC5:"e",\u1E19:"e",\u00EB:"e",\u0117:"e",\u1EB9:"e",\u0205:"e",\u00E8:"e",\u1EBB:"e",\u0207:"e",\u0113:"e",\u1E17:"e",\u1E15:"e","\u2C78":"e",\u0119:"e","\u1D92":"e","\u0247":"e",\u1EBD:"e",\u1E1B:"e","\uA76B":"et",\u1E1F:"f",\u0192:"f","\u1D6E":"f","\u1D82":"f",\u01F5:"g",\u011F:"g",\u01E7:"g",\u0123:"g",\u011D:"g",\u0121:"g",\u0260:"g",\u1E21:"g","\u1D83":"g",\u01E5:"g",\u1E2B:"h",\u021F:"h",\u1E29:"h",\u0125:"h","\u2C68":"h",\u1E27:"h",\u1E23:"h",\u1E25:"h",\u0266:"h",\u1E96:"h",\u0127:"h",\u0195:"hv",\u00ED:"i",\u012D:"i",\u01D0:"i",\u00EE:"i",\u00EF:"i",\u1E2F:"i",\u1ECB:"i",\u0209:"i",\u00EC:"i",\u1EC9:"i",\u020B:"i",\u012B:"i",\u012F:"i","\u1D96":"i",\u0268:"i",\u0129:"i",\u1E2D:"i","\uA77A":"d","\uA77C":"f","\u1D79":"g","\uA783":"r","\uA785":"s","\uA787":"t","\uA76D":"is",\u01F0:"j",\u0135:"j",\u029D:"j","\u0249":"j",\u1E31:"k",\u01E9:"k",\u0137:"k","\u2C6A":"k","\uA743":"k",\u1E33:"k",\u0199:"k",\u1E35:"k","\u1D84":"k","\uA741":"k","\uA745":"k",\u013A:"l",\u019A:"l",\u026C:"l",\u013E:"l",\u013C:"l",\u1E3D:"l","\u0234":"l",\u1E37:"l",\u1E39:"l","\u2C61":"l","\uA749":"l",\u1E3B:"l",\u0140:"l",\u026B:"l","\u1D85":"l",\u026D:"l",\u0142:"l",\u01C9:"lj",\u017F:"s","\u1E9C":"s",\u1E9B:"s","\u1E9D":"s",\u1E3F:"m",\u1E41:"m",\u1E43:"m",\u0271:"m","\u1D6F":"m","\u1D86":"m",\u0144:"n",\u0148:"n",\u0146:"n",\u1E4B:"n","\u0235":"n",\u1E45:"n",\u1E47:"n",\u01F9:"n",\u0272:"n",\u1E49:"n",\u019E:"n","\u1D70":"n","\u1D87":"n",\u0273:"n",\u00F1:"n",\u01CC:"nj",\u00F3:"o",\u014F:"o",\u01D2:"o",\u00F4:"o",\u1ED1:"o",\u1ED9:"o",\u1ED3:"o",\u1ED5:"o",\u1ED7:"o",\u00F6:"o",\u022B:"o",\u022F:"o",\u0231:"o",\u1ECD:"o",\u0151:"o",\u020D:"o",\u00F2:"o",\u1ECF:"o",\u01A1:"o",\u1EDB:"o",\u1EE3:"o",\u1EDD:"o",\u1EDF:"o",\u1EE1:"o",\u020F:"o","\uA74B":"o","\uA74D":"o","\u2C7A":"o",\u014D:"o",\u1E53:"o",\u1E51:"o",\u01EB:"o",\u01ED:"o",\u00F8:"o",\u01FF:"o",\u00F5:"o",\u1E4D:"o",\u1E4F:"o",\u022D:"o",\u01A3:"oi","\uA74F":"oo",\u025B:"e","\u1D93":"e",\u0254:"o","\u1D97":"o",\u0223:"ou",\u1E55:"p",\u1E57:"p","\uA753":"p",\u01A5:"p","\u1D71":"p","\u1D88":"p","\uA755":"p","\u1D7D":"p","\uA751":"p","\uA759":"q",\u02A0:"q","\u024B":"q","\uA757":"q",\u0155:"r",\u0159:"r",\u0157:"r",\u1E59:"r",\u1E5B:"r",\u1E5D:"r",\u0211:"r",\u027E:"r","\u1D73":"r",\u0213:"r",\u1E5F:"r",\u027C:"r","\u1D72":"r","\u1D89":"r","\u024D":"r",\u027D:"r","\u2184":"c","\uA73F":"c",\u0258:"e",\u027F:"r",\u015B:"s",\u1E65:"s",\u0161:"s",\u1E67:"s",\u015F:"s",\u015D:"s",\u0219:"s",\u1E61:"s",\u1E63:"s",\u1E69:"s",\u0282:"s","\u1D74":"s","\u1D8A":"s","\u023F":"s",\u0261:"g","\u1D11":"o","\u1D13":"o","\u1D1D":"u",\u0165:"t",\u0163:"t",\u1E71:"t",\u021B:"t","\u0236":"t",\u1E97:"t","\u2C66":"t",\u1E6B:"t",\u1E6D:"t",\u01AD:"t",\u1E6F:"t","\u1D75":"t",\u01AB:"t",\u0288:"t",\u0167:"t","\u1D7A":"th",\u0250:"a","\u1D02":"ae",\u01DD:"e","\u1D77":"g",\u0265:"h","\u02AE":"h","\u02AF":"h","\u1D09":"i",\u029E:"k","\uA781":"l",\u026F:"m",\u0270:"m","\u1D14":"oe",\u0279:"r",\u027B:"r",\u027A:"r","\u2C79":"r",\u0287:"t",\u028C:"v",\u028D:"w",\u028E:"y","\uA729":"tz",\u00FA:"u",\u016D:"u",\u01D4:"u",\u00FB:"u",\u1E77:"u",\u00FC:"u",\u01D8:"u",\u01DA:"u",\u01DC:"u",\u01D6:"u",\u1E73:"u",\u1EE5:"u",\u0171:"u",\u0215:"u",\u00F9:"u",\u1EE7:"u",\u01B0:"u",\u1EE9:"u",\u1EF1:"u",\u1EEB:"u",\u1EED:"u",\u1EEF:"u",\u0217:"u",\u016B:"u",\u1E7B:"u",\u0173:"u","\u1D99":"u",\u016F:"u",\u0169:"u",\u1E79:"u",\u1E75:"u","\u1D6B":"ue","\uA778":"um","\u2C74":"v","\uA75F":"v",\u1E7F:"v",\u028B:"v","\u1D8C":"v","\u2C71":"v",\u1E7D:"v","\uA761":"vy",\u1E83:"w",\u0175:"w",\u1E85:"w",\u1E87:"w",\u1E89:"w",\u1E81:"w","\u2C73":"w",\u1E98:"w",\u1E8D:"x",\u1E8B:"x","\u1D8D":"x",\u00FD:"y",\u0177:"y",\u00FF:"y",\u1E8F:"y",\u1EF5:"y",\u1EF3:"y",\u01B4:"y",\u1EF7:"y","\u1EFF":"y",\u0233:"y",\u1E99:"y","\u024F":"y",\u1EF9:"y",\u017A:"z",\u017E:"z",\u1E91:"z",\u0291:"z","\u2C6C":"z",\u017C:"z",\u1E93:"z",\u0225:"z",\u1E95:"z","\u1D76":"z","\u1D8E":"z",\u0290:"z",\u01B6:"z","\u0240":"z",\u00FE:"th",\uFB00:"ff",\uFB03:"ffi",\uFB04:"ffl",\uFB01:"fi",\uFB02:"fl",\u0133:"ij",\u0153:"oe",\uFB06:"st","\u2090":"a","\u2091":"e","\u1D62":"i","\u2C7C":"j","\u2092":"o","\u1D63":"r","\u1D64":"u","\u1D65":"v","\u2093":"x",\u0401:"YO",\u0419:"I",\u0426:"TS",\u0423:"U",\u041A:"K",\u0415:"E",\u041D:"N",\u0413:"G",\u0428:"SH",\u0429:"SCH",\u0417:"Z",\u0425:"H",\u042A:"'",\u0451:"yo",\u0439:"i",\u0446:"ts",\u0443:"u",\u043A:"k",\u0435:"e",\u043D:"n",\u0433:"g",\u0448:"sh",\u0449:"sch",\u0437:"z",\u0445:"h",\u044A:"'",\u0424:"F",\u042B:"I",\u0412:"V",\u0410:"a",\u041F:"P",\u0420:"R",\u041E:"O",\u041B:"L",\u0414:"D",\u0416:"ZH",\u042D:"E",\u0444:"f",\u044B:"i",\u0432:"v",\u0430:"a",\u043F:"p",\u0440:"r",\u043E:"o",\u043B:"l",\u0434:"d",\u0436:"zh",\u044D:"e",\u042F:"Ya",\u0427:"CH",\u0421:"S",\u041C:"M",\u0418:"I",\u0422:"T",\u042C:"'",\u0411:"B",\u042E:"YU",\u044F:"ya",\u0447:"ch",\u0441:"s",\u043C:"m",\u0438:"i",\u0442:"t",\u044C:"'",\u0431:"b",\u044E:"yu"};function I(e,n={}){$e(),typeof n.idSecPwd>"u"&&(n.idSecPwd=!0),typeof n.escapeAll>"u"&&(n.escapeAll=0),typeof n.accent>"u"&&(n.accent=0),typeof n.lowerCase>"u"&&(n.lowerCase=0),typeof n.leetSpeak>"u"&&(n.leetSpeak=0);const t=n.escapeAll===1?P(e):n.escapeAll===2?`${e} ${P(e)}`:e,o=Y(t),i=fe(o),r=Ue(i),c=Le(r).split(` `),f=`(${ze(c).map(ee=>ue(ee,n)).join("|")})`.replace(/§void§\|/g,"").replace(/\|§void§/g,"").replace(/§void§/g,"");if(f.includes("\xA7infiniteRecursion\xA7"))throw new Error(`Unable to parse : ${C(l(f))}`);if(!n.idSecPwd)return S(f,c);const x=ce("@@",h(f)),b=[];x.matching&&b.push(x.matching),x.notMatching&&b.push(x.notMatching);const X=Re(b);return S(X,c)}function fe(e){e=e.replace(/(^|\n)([^:\n]+)::/g,(t,o,i)=>`${o}\xA7!\xA7${i}::`),e=e.replace(/<([^<=>]+)>/g,(t,o)=>`<\xA7!\xA7${o}>`),e=e.replace(/=([^<=>]+)>/g,(t,o)=>`=\xA7!\xA7${o}>`);let n=9312;for(;;)try{let t=e.match(/§!§([^<:=>]+)(::|>)/)[1];e=e.replace(new RegExp(`\xA7!\xA7${t}(::|>)`,"g"),(o,i)=>`${String.fromCharCode(n)}${i}`),n++}catch{break}return e}function ue(e,n){return n.accent===1&&(e=V(e)),n.accent===2&&(e=le(e)),n.lowerCase===1&&(e=pe(e)),n.lowerCase===2&&(e=de(e)),n.leetSpeak===1&&(e=W(e)),n.leetSpeak===2&&(e=B(e)),n.leetSpeak===3&&(e=ye(e)),e}function S(e,n,t){let o=ke(e,n);if(o.match(/=[^>]+>/))throw new Error(`Unable to parse : ${C(l(o))}`);return C(l(o))}function d(e,n){const t=n(e);return t===e?e:`(${e}|${t})`}function z(e,n){return e.split("").map(n).join("")}function V(e){return d(e,G)}function le(e){return z(e,V)}function pe(e){return l(`(${Ce(e)}|${he(e)}|${q(e)})`)}function de(e){return l(`(${e.toUpperCase()}|${me(e)})`)}function q(e){return d(e,n=>n.toLowerCase())}function he(e){return d(e,n=>n.toUpperCase())}function ge(e){return z(e,q)}function Ce(e){let n=d(l(e),o=>o.split(" ").map(i=>i.charAt(0).toUpperCase()+i.slice(1)).join(" ")),t=d(l(e),o=>o.split(" ").map(i=>i.charAt(0).toUpperCase()+i.slice(1).toLowerCase()).join(" "));return d(n,()=>t)}function me(e){let n=e.split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ");return ge(n)}function Ae(e){return d(e,xe)}function B(e){return d(e,Ee)}function W(e){return z(e,Ae)}function ye(e){return W(z(e,B))}function Oe(e,n){return e.split("").map(t=>n[t]||t).join("")}function we(e,n){return e.split("").map(t=>n[t.toUpperCase()]||t).join("")}function Ee(e){return we(e,{O:"0",I:"1",L:"1",R:"2",Z:"2",E:"3",A:"4",S:"(5|$)",G:"(6|9)",T:"(7|1)",Y:"7",B:"(8|6)"})}function xe(e){return Oe(e,{$:"(s|S)",0:"(o|O)",1:"(i|l|I|L|t|T)",2:"(r|R|z|Z)",3:"(e|E)",4:"(a|A)",5:"(s|S)",6:"(g|G|b|B)",7:"(t|T|y|Y)",8:"(b|B)",9:"(g|G)"})}function l(e){return m(h(e))}function $e(){p()}function p(e,n,...t){return p.cached||(p.cached={}),arguments.length===0?p.cached={}:(typeof p.cached[e]>"u"&&(p.cached[e]=n(...t)),p.cached[e])}function Ue(e){const n="abcdefghijklmnopqrstuvwxyz",t=n.toUpperCase(),o="0123456789";return e=e.replace(/(\[[^\]]*)([a-z]-[a-z])([^\]]*])/g,(i,r,a,c)=>r+n.slice(n.indexOf(a.split("-")[0]),n.indexOf(a.split("-")[1])+1)+c),e=e.replace(/(\[[^\]]*)([A-Z]-[A-Z])([^\]]*])/g,(i,r,a,c)=>r+t.slice(t.indexOf(a.split("-")[0]),t.indexOf(a.split("-")[1])+1)+c),e=e.replace(/(\[[^\]]*)([0-9]-[0-9])([^\]]*])/g,(i,r,a,c)=>r+o.slice(o.indexOf(a.split("-")[0]),o.indexOf(a.split("-")[1])+1)+c),e=e.replace(/\[([^\]]+)]/g,(i,r)=>`(${r.split("").join("|")})`),e}function H(e,n,t){const o=t.split(",").map(c=>parseInt(c.trim())),i=o[0],r=o.length===2?o[1]:i;if(isNaN(i)||isNaN(r))throw`Error, invalid quantity : ${t}`;let a=n.repeat(i);if(r>i){a+="(";for(let c=0;c<=r-i;c++)a+=`|${n.repeat(c)}`;a+=")"}return a}function Le(e){for(e=e.replace(/([^>)]){([^}]+)}/g,H);;){const n=U(e,"{","}");if(!n.before||!n.inside)break;const t=je(n.before);e=t.before+H("",t.inside,n.inside)+n.after}return e}function je(e){let n=[U(e,"(",")"),U(e,"<",">"),U(e,"=",">")];return n[0].inside=`(${n[0].inside})`,n[1].inside=`<${n[1].inside}>`,n[2].inside=`=${n[2].inside}>`,n=n.filter(t=>t.after.length===0).filter(t=>t.inside.length>2),n.length===1||n[0].inside.length<n[1].inside.length?n[0]:n[1]}function U(e,n,t){const o=e.split(""),i={before:"",inside:"",after:""};function r(){for(;o.length;){const a=o.pop();if(i.inside=a+i.inside,a===n)return;a===t&&r()}}for(;o.length;){const a=o.pop();if(a!==t&&(i.after=a+i.after),a===t)return r(),i.inside=i.inside.substring(1),i.before=o.join(""),i}return i}function ze(e){return e.map(n=>F(n,e))}function F(e,n,t=">"){return e.includes("::")?"\xA7void\xA7":(e=be(e,n,t),e)}function be(e,n,t){return e=e.replace(/<([^>]+)>/g,(o,i)=>_(i,n,t)),e}function ke(e,n,t=">"){const o={};return e.replace(/=([^>]+)>/g,(i,r)=>o[r]=_(r,n,t)),Object.keys(o).forEach(i=>{const r=[],a=h(o[i]),c=D(a);for(let s=0;s<c;s++){const E=se(s,a);r.push(e.replace(new RegExp(`=${i}>`,"g"),E))}e=l(`(${r.join("|")})`)}),e}function _(e,n,t){return p(`label::${e}`,Te,e,n,t)}function Te(e,n,t){if(t.includes(e))return"\xA7infiniteRecursion\xA7";t+=e+">";const o=n.filter(i=>i.trim().indexOf(`${e}::`)===0);return l(`(${o.map(i=>F(Ne(i),n,t)).join("|")})`)}function Ne(e){return e.slice(e.indexOf("::")+2)}function Re(e){const n=[],t=[];return e.forEach(o=>o.includes("@@")?n.push(o):t.push(o)),t.length&&n.push(`${T(t)}@@${T(t)}`),T(n)}function T(e){return e.length?(e=e.filter(n=>n.length),e.length===1?e[0]:`(${e.join("|")})`):""}class De{constructor(n,t={}){if(this.originalConfig=t,this.originalConfig.dictionaryString=n,this.config=JSON.parse(JSON.stringify(this.originalConfig)),typeof this.config.cache>"u"&&(this.config.cache=!0),typeof this.config.cacheMax>"u"&&(this.config.cacheMax=1e6),typeof this.config.idSecPwd>"u"&&(this.config.idSecPwd=!0),this.originalConfig.escapeAll!==1)try{this.config.escapeAll=0,this.tree=h(I(n,this.config)),this.config.escapeAll=this.originalConfig.escapeAll}catch{this.config.escapeAll=1}this.tree=h(I(n,this.config)),this.length=this.tree.altCount,this.estimateDuration=()=>this.length/(this.config.speed||1),this.estimateRemaining=()=>(this.length-this.tried)/(this.config.speed||1),this.config.speed&&Ie(this),this.tried=0,this.cache=[],this.duplicatedCount=()=>Object.keys(this.cache).length?this.tried-Object.keys(this.cache).length:0,this.dryGet=i=>O(this.rawDryGet(i)),this.rawDryGet=i=>v(i,this.tree),this.get=i=>O(this.rawGet(i)),this.rawGet=i=>{typeof this.startTime>"u"&&(this.startTime=Date.now()),this.tried++;const r=v(i,this.tree);return this.config.cache&&this.length<this.config.cacheMax&&(typeof this.cache[r]>"u"&&(this.cache[r]=[]),this.cache[r].push(i),this.cache[r].length>1)?`\xA7duplicate\xA7${r}`:r};function o(i){const r=i.split("@@"),a=O(r[0]),c=O(r[r.length-1]),s=[a,c];return s.idSec=a,s.pwd=c,s.pass=c,s}this.splitGet=i=>o(this.rawGet(i)),this.splitDryGet=i=>o(this.rawDryGet(i)),this.timeSpent=()=>(Date.now()-this.startTime)/1e3,this.duplicatedFound=()=>{const i=[];for(let a of Object.keys(this.cache))this.cache[a].length>1&&i.push({alt:a,index:this.cache[a]});return i.sort((a,c)=>c.index.length-a.index.length)},this.dryRunDedup=()=>Q(this),this.serialize=()=>M(this.tree)}}function $(e){return e===-1||typeof e>"u"||e==="auto"||e==="-1"}function Ie(e){if(e.estimateDuration()>=3600||e.length>=e.config.cacheMax)return;function t(i){i.tree=h(I(i.originalConfig.dictionaryString,i.config)),i.length=i.tree.altCount}let o;for(;e.estimateDuration()<3600&&e.length<e.config.cacheMax;){if(o=JSON.parse(JSON.stringify(e.config)),e.config.escapeAll!==2&&$(e.originalConfig.escapeAll)){e.config.escapeAll=2,t(e);continue}if(e.config.accent!==2&&$(e.originalConfig.accent)){e.config.accent?e.config.accent++:e.config.accent=1,t(e);continue}if(e.config.lowerCase!==2&&$(e.originalConfig.lowerCase)){e.config.lowerCase?e.config.lowerCase++:e.config.lowerCase=1,t(e);continue}if(e.config.leetSpeak!==3&&$(e.originalConfig.leetSpeak)){e.config.leetSpeak?e.config.leetSpeak++:e.config.leetSpeak=1,t(e);continue}break}e.config=o||e.config,t(e),Q(e)}function Q(e){const n=new De(M(e.tree),{cache:!0,idSecPwd:!1});for(let o=0;o<n.length;o++)n.get(o);const t=n.duplicatedFound();return e.duplicateTotal=n.duplicatedCount(),e.duplicateRatio=e.duplicateTotal/e.length,e.uniqueRatio=1-e.duplicateRatio,t}export{De as Dictionary};