g1lib
Version:
An ubiquitous static javascript toolbox lib for Ǧ1 / Duniter ecosystem with reliability in mind.
4 lines (3 loc) • 20.3 kB
JavaScript
function I(e){return typeof e=="string"?e.replace(/[^A-Za-z0-9]/g,function(n){return I.characters[n]||n}):e}I.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"};const A={"(":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)},U=W(A);function W(e){const n={};for(const t in e)n[e[t]]=t;return n}function P(e){return e.replace(/\\(.)/g,(n,t)=>A[t]?A[t]:t)}function F(e){return e.split("").map(n=>U[n]?U[n]:n).join("")}function g(e){return e.split("").map(n=>U[n]?`\\${U[n]}`:n).join("")}function v(e){return e.replace(/./g,n=>A[n]?A[n]:n)}function E(e){const n=P(e).split(""),t=Y(n);if(n.length)throw new Error(`fail to build tree from : "${g(e)}" parsed: ${JSON.stringify(t)} unparsed/failed: ${g(n.join(""))}`);let o,r=t;do o=JSON.stringify(r),r=Z(r);while(JSON.stringify(r)!==o);return b(r),r}function h(e){e.str.length&&e.tree.alt[e.tree.alt.length-1].step.push({str:e.str}),e.str=""}function H(e,n){n.str+=e}function Q(e){e.tree.alt.push({step:[]})}function X(e){e.tree.alt[e.tree.alt.length-1].step.push(Y(e.input))}function _(){return!0}const z={")":(e,n)=>_(h(n)),"|":(e,n)=>(h(n),Q(n),void 0),"(":(e,n)=>(h(n),X(n),void 0),default:(e,n)=>H(e,n)};function Y(e){const n={input:e,str:"",tree:{alt:[{step:[]}]}};for(;n.input.length;){const t=n.input.shift();if(typeof z[t]<"u"){if(z[t](t,n))return n.tree}else z.default(t,n)}return h(n),n.tree}function ee(e){const n={input:e,str:"",tree:{alt:[{step:[]}]}};return e.forEach(t=>{m(t)?H(t.str,n):(h(n),n.tree.alt[n.tree.alt.length-1].step.push(t))}),h(n),n.tree.alt[n.tree.alt.length-1].step}function Z(e){if(m(e))return e;const n=u(e)?"alt":"step";if(e[n]=e[n].map(Z),e[n].length===0)return{str:""};if(e[n].length===1)return e[n][0];if(u(e))return e.alt=ne(e.alt),e.alt=[].concat(...e.alt.map(t=>u(t)?t.alt:[t])),e;if(O(e))return e.step=ee(e.step),e}function m(e){return typeof e=="object"&&typeof e.str=="string"}function O(e){return typeof e=="object"&&typeof e.step<"u"}function u(e){return typeof e=="object"&&typeof e.alt<"u"}function ne(e){const n={};return e.forEach(t=>n[JSON.stringify(t)]=t),Object.keys(n).sort().map(JSON.parse)}function te(e,n){function t(o){if(m(o)){if(!o.str.includes(e))return{notMatching:o.str};if(o.str.split(e).length>2)throw new Error("Error: @@ can only appear once in expression (idSec at left, password \xE0 right)");return{matching:o.str}}if(O(o)){let r=0,a=!1,f="",s="";if(o.step.forEach(y=>{const c=t(y);c.matching?(r++,typeof c.notMatching<"u"&&(a=!0),f+=c.matching,s+=c.notMatching):(f+=c.notMatching,s+=c.notMatching)}),r>1)throw new Error("Error: @@ can only appear once in expression (idSec at left, password \xE0 right)");return r&&a?{matching:f,notMatching:s}:r?{matching:f}:{notMatching:f}}if(u(o)){const r=[],a=[];if(o.alt.forEach(f=>{const s=t(f);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(o)}`)}const i=t(n);return typeof i.matching<"u"&&(i.matching=C(E(i.matching))),typeof i.notMatching<"u"&&(i.notMatching=C(E(i.notMatching))),i}function ie(e){return g(C(e))}function C(e){if(m(e))return e.str;if(O(e))return e.step.map(C).join("");if(u(e))return`(${e.alt.map(C).join("|")})`;throw new Error(`Error: how to serialize ${JSON.stringify(e)} RAW: ${e}`)}function b(e){if(m(e))return e.altCount=1,e.indexCost=1,1;if(u(e))return e.altCount=e.alt.reduce((n,t)=>n+b(t),0),e.indexCost=e.altCount-1,e.altCount;if(O(e)){e.altCount=e.step.reduce((t,i)=>t*b(i),1);let n=1;for(let t=e.step.length-1;t>=0;t--){const i=e.step[t];u(i)&&(i.alt.forEach(o=>T(o,n)),n*=i.altCount)}return e.indexCost=e.altCount,e.altCount}}function T(e,n){e.indexCost*=n,O(e)&&e.step.forEach(t=>T(t,n)),u(e)&&e.alt.forEach(t=>T(t,n))}function k(e){return e.altCount}function oe(e,n){return F(N({index:e},n))}function N(e,n){if(m(n))return n.str;if(O(n))return n.step.map(t=>N(e,t)).join("");if(u(n))for(const t of n.alt){if(e.index<t.indexCost)return N(e,t);e.index-=t.indexCost}throw new Error(`index out of bound : ${e.index+k(n)} asked, 0-${k(n)-1} available in ${ie(n)}`)}function Te(e,n={}){Ee(),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?v(e):n.escapeAll===2?`${e}
${v(e)}`:e,i=P(t),o=re(i),r=ye(o),f=we(r).split(`
`),c=`(${Ue(f).map(S=>ae(S,n)).join("|")})`.replace(/§void§\|/g,"").replace(/\|§void§/g,"").replace(/§void§/g,"");if(c.includes("\xA7infiniteRecursion\xA7"))throw new Error(`Unable to parse : ${g(l(c))}`);if(!n.idSecPwd)return M(c,f);const w=te("@@",E(c)),L=[];w.matching&&L.push(w.matching),w.notMatching&&L.push(w.notMatching);const B=be(L);return M(B,f)}function re(e){e=e.replace(/(^|\n)([^:\n]+)::/g,(t,i,o)=>`${i}\xA7!\xA7${o}::`),e=e.replace(/<([^<=>]+)>/g,(t,i)=>`<\xA7!\xA7${i}>`),e=e.replace(/=([^<=>]+)>/g,(t,i)=>`=\xA7!\xA7${i}>`);let n=9312;for(;;)try{let t=e.match(/§!§([^<:=>]+)(::|>)/)[1];e=e.replace(new RegExp(`\xA7!\xA7${t}(::|>)`,"g"),(i,o)=>`${String.fromCharCode(n)}${o}`),n++}catch{break}return e}function ae(e,n){return n.accent===1&&(e=D(e)),n.accent===2&&(e=fe(e)),n.lowerCase===1&&(e=se(e)),n.lowerCase===2&&(e=ce(e)),n.leetSpeak===1&&(e=V(e)),n.leetSpeak===2&&(e=K(e)),n.leetSpeak===3&&(e=ge(e)),e}function M(e,n,t){let i=Le(e,n);if(i.match(/=[^>]+>/))throw new Error(`Unable to parse : ${g(l(i))}`);return g(l(i))}function d(e,n){const t=n(e);return t===e?e:`(${e}|${t})`}function x(e,n){return e.split("").map(n).join("")}function D(e){return d(e,I)}function fe(e){return x(e,D)}function se(e){return l(`(${pe(e)}|${ue(e)}|${G(e)})`)}function ce(e){return l(`(${e.toUpperCase()}|${de(e)})`)}function G(e){return d(e,n=>n.toLowerCase())}function ue(e){return d(e,n=>n.toUpperCase())}function le(e){return x(e,G)}function pe(e){let n=d(l(e),i=>i.split(" ").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ")),t=d(l(e),i=>i.split(" ").map(o=>o.charAt(0).toUpperCase()+o.slice(1).toLowerCase()).join(" "));return d(n,()=>t)}function de(e){let n=e.split(" ").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ");return le(n)}function he(e){return d(e,Ae)}function K(e){return d(e,Oe)}function V(e){return x(e,he)}function ge(e){return V(x(e,K))}function Ce(e,n){return e.split("").map(t=>n[t]||t).join("")}function me(e,n){return e.split("").map(t=>n[t.toUpperCase()]||t).join("")}function Oe(e){return me(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 Ae(e){return Ce(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 C(E(e))}function Ee(){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 ye(e){const n="abcdefghijklmnopqrstuvwxyz",t=n.toUpperCase(),i="0123456789";return e=e.replace(/(\[[^\]]*)([a-z]-[a-z])([^\]]*])/g,(o,r,a,f)=>r+n.slice(n.indexOf(a.split("-")[0]),n.indexOf(a.split("-")[1])+1)+f),e=e.replace(/(\[[^\]]*)([A-Z]-[A-Z])([^\]]*])/g,(o,r,a,f)=>r+t.slice(t.indexOf(a.split("-")[0]),t.indexOf(a.split("-")[1])+1)+f),e=e.replace(/(\[[^\]]*)([0-9]-[0-9])([^\]]*])/g,(o,r,a,f)=>r+i.slice(i.indexOf(a.split("-")[0]),i.indexOf(a.split("-")[1])+1)+f),e=e.replace(/\[([^\]]+)]/g,(o,r)=>`(${r.split("").join("|")})`),e}function R(e,n,t){const i=t.split(",").map(f=>parseInt(f.trim())),o=i[0],r=i.length===2?i[1]:o;if(isNaN(o)||isNaN(r))throw`Error, invalid quantity : ${t}`;let a=n.repeat(o);if(r>o){a+="(";for(let f=0;f<=r-o;f++)a+=`|${n.repeat(f)}`;a+=")"}return a}function we(e){for(e=e.replace(/([^>)]){([^}]+)}/g,R);;){const n=$(e,"{","}");if(!n.before||!n.inside)break;const t=$e(n.before);e=t.before+R("",t.inside,n.inside)+n.after}return e}function $e(e){let n=[$(e,"(",")"),$(e,"<",">"),$(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 $(e,n,t){const i=e.split(""),o={before:"",inside:"",after:""};function r(){for(;i.length;){const a=i.pop();if(o.inside=a+o.inside,a===n)return;a===t&&r()}}for(;i.length;){const a=i.pop();if(a!==t&&(o.after=a+o.after),a===t)return r(),o.inside=o.inside.substring(1),o.before=i.join(""),o}return o}function Ue(e){return e.map(n=>J(n,e))}function J(e,n,t=">"){return e.includes("::")?"\xA7void\xA7":(e=xe(e,n,t),e)}function xe(e,n,t){return e=e.replace(/<([^>]+)>/g,(i,o)=>q(o,n,t)),e}function Le(e,n,t=">"){const i={};return e.replace(/=([^>]+)>/g,(o,r)=>i[r]=q(r,n,t)),Object.keys(i).forEach(o=>{const r=[],a=E(i[o]),f=k(a);for(let s=0;s<f;s++){const y=oe(s,a);r.push(e.replace(new RegExp(`=${o}>`,"g"),y))}e=l(`(${r.join("|")})`)}),e}function q(e,n,t){return p(`label::${e}`,ze,e,n,t)}function ze(e,n,t){if(t.includes(e))return"\xA7infiniteRecursion\xA7";t+=e+">";const i=n.filter(o=>o.trim().indexOf(`${e}::`)===0);return l(`(${i.map(o=>J(je(o),n,t)).join("|")})`)}function je(e){return e.slice(e.indexOf("::")+2)}function be(e){const n=[],t=[];return e.forEach(i=>i.includes("@@")?n.push(i):t.push(i)),t.length&&n.push(`${j(t)}@@${j(t)}`),j(n)}function j(e){return e.length?(e=e.filter(n=>n.length),e.length===1?e[0]:`(${e.join("|")})`):""}export{Te as parse};