cmpstr 3.1.0 → 3.1.1

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.
Files changed (83) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +1 -1
  3. package/dist/CmpStr.esm.js +37 -25
  4. package/dist/CmpStr.esm.js.map +1 -1
  5. package/dist/CmpStr.esm.min.js +2 -2
  6. package/dist/CmpStr.esm.min.js.map +1 -1
  7. package/dist/CmpStr.umd.js +37 -21
  8. package/dist/CmpStr.umd.js.map +1 -1
  9. package/dist/CmpStr.umd.min.js +2 -2
  10. package/dist/CmpStr.umd.min.js.map +1 -1
  11. package/dist/cjs/CmpStr.cjs +1 -1
  12. package/dist/cjs/CmpStrAsync.cjs +1 -1
  13. package/dist/cjs/index.cjs +1 -1
  14. package/dist/cjs/metric/Cosine.cjs +1 -1
  15. package/dist/cjs/metric/DamerauLevenshtein.cjs +1 -1
  16. package/dist/cjs/metric/DiceSorensen.cjs +1 -1
  17. package/dist/cjs/metric/Hamming.cjs +1 -1
  18. package/dist/cjs/metric/Jaccard.cjs +1 -1
  19. package/dist/cjs/metric/JaroWinkler.cjs +1 -1
  20. package/dist/cjs/metric/LCS.cjs +1 -1
  21. package/dist/cjs/metric/Levenshtein.cjs +1 -1
  22. package/dist/cjs/metric/Metric.cjs +1 -1
  23. package/dist/cjs/metric/NeedlemanWunsch.cjs +1 -1
  24. package/dist/cjs/metric/SmithWaterman.cjs +1 -1
  25. package/dist/cjs/metric/qGram.cjs +1 -1
  26. package/dist/cjs/phonetic/Caverphone.cjs +1 -1
  27. package/dist/cjs/phonetic/Cologne.cjs +1 -1
  28. package/dist/cjs/phonetic/Metaphone.cjs +1 -1
  29. package/dist/cjs/phonetic/Phonetic.cjs +1 -1
  30. package/dist/cjs/phonetic/Soundex.cjs +1 -1
  31. package/dist/cjs/root.cjs +1 -1
  32. package/dist/cjs/utils/DeepMerge.cjs +1 -1
  33. package/dist/cjs/utils/DiffChecker.cjs +1 -1
  34. package/dist/cjs/utils/Filter.cjs +1 -1
  35. package/dist/cjs/utils/HashTable.cjs +6 -6
  36. package/dist/cjs/utils/HashTable.cjs.map +1 -1
  37. package/dist/cjs/utils/Normalizer.cjs +1 -1
  38. package/dist/cjs/utils/Pool.cjs +6 -6
  39. package/dist/cjs/utils/Pool.cjs.map +1 -1
  40. package/dist/cjs/utils/Profiler.cjs +1 -1
  41. package/dist/cjs/utils/Registry.cjs +1 -1
  42. package/dist/cjs/utils/StructuredData.cjs +27 -15
  43. package/dist/cjs/utils/StructuredData.cjs.map +1 -1
  44. package/dist/cjs/utils/TextAnalyzer.cjs +1 -1
  45. package/dist/esm/CmpStr.mjs +1 -1
  46. package/dist/esm/CmpStrAsync.mjs +1 -1
  47. package/dist/esm/index.mjs +1 -1
  48. package/dist/esm/metric/Cosine.mjs +1 -1
  49. package/dist/esm/metric/DamerauLevenshtein.mjs +1 -1
  50. package/dist/esm/metric/DiceSorensen.mjs +1 -1
  51. package/dist/esm/metric/Hamming.mjs +1 -1
  52. package/dist/esm/metric/Jaccard.mjs +1 -1
  53. package/dist/esm/metric/JaroWinkler.mjs +1 -1
  54. package/dist/esm/metric/LCS.mjs +1 -1
  55. package/dist/esm/metric/Levenshtein.mjs +1 -1
  56. package/dist/esm/metric/Metric.mjs +1 -1
  57. package/dist/esm/metric/NeedlemanWunsch.mjs +1 -1
  58. package/dist/esm/metric/SmithWaterman.mjs +1 -1
  59. package/dist/esm/metric/qGram.mjs +1 -1
  60. package/dist/esm/phonetic/Caverphone.mjs +1 -1
  61. package/dist/esm/phonetic/Cologne.mjs +1 -1
  62. package/dist/esm/phonetic/Metaphone.mjs +1 -1
  63. package/dist/esm/phonetic/Phonetic.mjs +1 -1
  64. package/dist/esm/phonetic/Soundex.mjs +1 -1
  65. package/dist/esm/root.mjs +1 -1
  66. package/dist/esm/utils/DeepMerge.mjs +1 -1
  67. package/dist/esm/utils/DiffChecker.mjs +1 -1
  68. package/dist/esm/utils/Filter.mjs +1 -1
  69. package/dist/esm/utils/HashTable.mjs +6 -6
  70. package/dist/esm/utils/HashTable.mjs.map +1 -1
  71. package/dist/esm/utils/Normalizer.mjs +1 -1
  72. package/dist/esm/utils/Pool.mjs +6 -6
  73. package/dist/esm/utils/Pool.mjs.map +1 -1
  74. package/dist/esm/utils/Profiler.mjs +1 -1
  75. package/dist/esm/utils/Registry.mjs +1 -1
  76. package/dist/esm/utils/StructuredData.mjs +27 -15
  77. package/dist/esm/utils/StructuredData.mjs.map +1 -1
  78. package/dist/esm/utils/TextAnalyzer.mjs +1 -1
  79. package/dist/types/index.d.ts +2 -2
  80. package/dist/types/root.d.ts +1 -1
  81. package/dist/types/utils/StructuredData.d.ts +13 -11
  82. package/dist/types/utils/Types.d.ts +8 -0
  83. package/package.json +3 -2
@@ -1,8 +1,8 @@
1
1
  /**
2
- * CmpStr v3.1.0 build-76aadb9-260117
2
+ * CmpStr v3.1.1 build-a140f52-260119
3
3
  * This is a lightweight, fast and well performing library for calculating string similarity.
4
4
  * (c) 2023-2026 Paul Köhler @komed3 / MIT License
5
5
  * Visit https://github.com/komed3/cmpstr and https://npmjs.org/package/cmpstr
6
6
  */
7
- const t=t=>t.replace(/\[(\d+)]/g,".$1").split(".").map(t=>/^\d+$/.test(t)?+t:t);function e(e,r,s){return t(r).reduce((t,e)=>t?.[e]??s,e)}function r(e,s,n){if(""===s)return n;const[i,...a]=t(s);if(void 0!==e&&("object"!=typeof e||null===e))throw Error(`Cannot set property <${i}> of <${JSON.stringify(e)}>`);return Object.assign(e??("number"==typeof i?[]:Object.create(null)),{[i]:r(e?.[i],a.join("."),n)})}function s(t=Object.create(null),e=Object.create(null),r=!1){return Object.keys(e).forEach(n=>{const i=e[n];(r||void 0!==i)&&"__proto__"!==n&&"constructor"!==n&&(t[n]="object"!=typeof i||Array.isArray(i)?i:s("object"!=typeof t[n]||Array.isArray(t[n])?Object.create(null):t[n],i))}),t}function n(e,r,s=!1){const n=(t,e,r=0)=>{const i=e[r];if(!t||"object"!=typeof t)return!1;if(r===e.length-1)return delete t[i];if(!n(t[i],e,r+1))return!1;if(!s){const e=t[i];"object"==typeof e&&(Array.isArray(e)&&e.every(t=>null==t)||!Array.isArray(e)&&0===Object.keys(e).length)&&delete t[i]}return!0};return n(e,t(r)),e}var i=Object.freeze({__proto__:null,get:e,has:function(e,r){return void 0!==t(r).reduce((t,e)=>t&&e in t?t[e]:void 0,e)},merge:s,rmv:n,set:r});class a{static ENV;static instance;store=new Set;totalTime=0;totalMem=0;active;static detectEnv(){"undefined"!=typeof process?a.ENV="nodejs":"undefined"!=typeof performance?a.ENV="browser":a.ENV="unknown"}static getInstance(t){return a.ENV||a.detectEnv(),a.instance||(a.instance=new a(t)),a.instance}constructor(t){this.active=t??!1}now(){switch(a.ENV){case"nodejs":return Number(process.hrtime.bigint())/1e6;case"browser":return performance.now();default:return Date.now()}}mem(){switch(a.ENV){case"nodejs":return process.memoryUsage().heapUsed;case"browser":return performance.memory?.usedJSHeapSize??0;default:return 0}}enable(){this.active=!0}disable(){this.active=!1}clear(){this.store.clear(),this.totalTime=0,this.totalMem=0}run(t,e={}){if(!this.active)return t();const r=this.now(),s=this.mem(),n=t(),i=this.now()-r,a=this.mem()-s;return this.store.add({time:i,mem:a,res:n,meta:e}),this.totalTime+=i,this.totalMem+=a,n}async runAsync(t,e={}){if(!this.active)return await t();const r=this.now(),s=this.mem(),n=await t(),i=this.now()-r,a=this.mem()-s;return this.store.add({time:i,mem:a,res:n,meta:e}),this.totalTime+=i,this.totalMem+=a,n}getAll(){return[...this.store]}getLast(){return this.getAll().pop()}getTotal(){return{time:this.totalTime,mem:this.totalMem}}services={enable:this.enable.bind(this),disable:this.disable.bind(this),clear:this.clear.bind(this),report:this.getAll.bind(this),last:this.getLast.bind(this),total:this.getTotal.bind(this)}}class o{text;words=[];sentences=[];charFrequency=new Map;wordHistogram=new Map;syllableCache=new Map;constructor(t){this.text=t.trim(),this.tokenize(),this.computeFrequencies()}tokenize(){this.words=[],this.sentences=[];const t=this.text,e=/\p{L}+/gu;let r;for(;null!==(r=e.exec(t));)this.words.push(r[0].toLowerCase());this.sentences=t.split(/(?<=[.!?])\s+/).filter(Boolean)}computeFrequencies(){for(const t of this.text)this.charFrequency.set(t,(this.charFrequency.get(t)??0)+1);for(const t of this.words)this.wordHistogram.set(t,(this.wordHistogram.get(t)??0)+1)}estimateSyllables(t){if(this.syllableCache.has(t))return this.syllableCache.get(t);const e=t.toLowerCase().replace(/[^a-zäöüß]/g,"").match(/[aeiouyäöü]+/g),r=e?e.length:1;return this.syllableCache.set(t,r),r}getLength(){return this.text.length}getWordCount(){return this.words.length}getSentenceCount(){return this.sentences.length}getAvgWordLength(){let t=0;for(const e of this.words)t+=e.length;return this.words.length?t/this.words.length:0}getAvgSentenceLength(){return this.sentences.length?this.words.length/this.sentences.length:0}getWordHistogram(){return Object.fromEntries(this.wordHistogram)}getMostCommonWords(t=5){return[...this.wordHistogram.entries()].sort((t,e)=>e[1]-t[1]).slice(0,t).map(t=>t[0])}getHapaxLegomena(){return[...this.wordHistogram.entries()].filter(([,t])=>1===t).map(t=>t[0])}hasNumbers(){return/\d/.test(this.text)}getUpperCaseRatio(){let t=0,e=0;for(let r=0,s=this.text.length;r<s;r++){const s=this.text[r];/[A-Za-zÄÖÜäöüß]/.test(s)&&(e++,/[A-ZÄÖÜ]/.test(s)&&t++)}return e?t/e:0}getCharFrequency(){return Object.fromEntries(this.charFrequency)}getUnicodeStats(){const t={};for(const[e,r]of this.charFrequency){const s=e.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase();t[s]=(t[s]??0)+r}return t}getLongWordRatio(t=7){let e=0;for(const r of this.words)r.length>=t&&e++;return this.words.length?e/this.words.length:0}getShortWordRatio(t=3){let e=0;for(const r of this.words)r.length<=t&&e++;return this.words.length?e/this.words.length:0}getSyllablesCount(){let t=0;for(const e of this.words)t+=this.estimateSyllables(e);return t}getMonosyllabicWordCount(){let t=0;for(const e of this.words)1===this.estimateSyllables(e)&&t++;return t}getMinSyllablesWordCount(t){let e=0;for(const r of this.words)this.estimateSyllables(r)>=t&&e++;return e}getMaxSyllablesWordCount(t){let e=0;for(const r of this.words)this.estimateSyllables(r)<=t&&e++;return e}getHonoresR(){return 100*Math.log(this.words.length)/(1-this.getHapaxLegomena().length/(this.wordHistogram.size??1))}getReadingTime(t=200){return Math.max(1,this.words.length/(t??1))}getReadabilityScore(t="flesch"){const e=this.words.length||1,r=e/(this.sentences.length||1),s=(this.getSyllablesCount()||1)/e;switch(t){case"flesch":return 206.835-1.015*r-84.6*s;case"fleschde":return 180-r-58.5*s;case"kincaid":return.39*r+11.8*s-15.59}}getLIXScore(){const t=this.words.length||1;return t/(this.sentences.length||1)+this.getLongWordRatio()*t/t*100}getWSTFScore(){const t=this.words.length||1,e=this.getMinSyllablesWordCount(3)/t*100,r=this.getAvgSentenceLength(),s=100*this.getLongWordRatio();return[.1935*e+.1672*r+.1297*s-this.getMonosyllabicWordCount()/t*100*.0327-.875,.2007*e+.1682*r+.1373*s-2.779,.2963*e+.1905*r-1.1144,.2744*e+.2656*r-1.693]}}class c{a;b;options;entries=[];grouped=[];diffRun=!1;constructor(t,e,r={}){this.a=t,this.b=e,this.options={mode:"word",caseInsensitive:!1,contextLines:1,groupedLines:!0,expandLines:!1,showChangeMagnitude:!0,maxMagnitudeSymbols:5,lineBreak:"\n",...r},this.computeDiff()}text2lines(){const t=this.a.trim().split(/\r?\n/),e=this.b.trim().split(/\r?\n/);return{linesA:t,linesB:e,maxLen:Math.max(t.length,e.length)}}tokenize(t){const{mode:e}=this.options;switch(e){case"line":return[t];case"word":return t.split(/\s+/)}}concat(t){const{mode:e}=this.options;return t.join("word"===e?" ":"")}computeDiff(){if(!this.diffRun){const{linesA:t,linesB:e,maxLen:r}=this.text2lines();for(let s=0;s<r;s++){const r=t[s]||"",n=e[s]||"";this.lineDiff(r,n,s)}this.findGroups(),this.diffRun=!0}}lineDiff(t,e,r){const{mode:s,caseInsensitive:n}=this.options,i=Math.max(t.length,e.length);let a=t,o=e;n&&(a=t.toLowerCase(),o=e.toLowerCase());let c=[],l=0,h=0;if("line"===s)a!==o&&(c.push({posA:0,posB:0,del:t,ins:e,size:e.length-t.length}),l=t.length,h=e.length);else{c=this.preciseDiff(t,a,e,o);for(const t of c)l+=t.del.length,h+=t.ins.length}c.length&&this.entries.push({line:r,diffs:c,delSize:l,insSize:h,baseLen:i,totalSize:h-l,magnitude:this.magnitude(l,h,i)})}preciseDiff(t,e,r,s){const n=t=>t.reduce((e,r,s)=>(e.push(s?e[s-1]+t[s-1].length+1:0),e),[]),i=this.tokenize(t),a=this.tokenize(r),o=this.tokenize(e),c=this.tokenize(s),l=o.length,h=c.length,u=n(i),p=n(a),d=[];let g=0,m=0;for(;g<l&&m<h;)if(o[g]===c[m]){let t=1;for(;g+t<l&&m+t<h&&o[g+t]===c[m+t];)t++;d.push({ai:g,bi:m,len:t}),g+=t,m+=t}else{let t=!1;for(let e=1;e<=3&&!t;e++)g+e<l&&o[g+e]===c[m]?(d.push({ai:g+e,bi:m,len:1}),g+=e+1,m+=1,t=!0):m+e<h&&o[g]===c[m+e]&&(d.push({ai:g,bi:m+e,len:1}),g+=1,m+=e+1,t=!0);t||(g++,m++)}const f=[];let y=0,w=0;for(const t of d){if(y<t.ai||w<t.bi){const e=i.slice(y,t.ai),r=a.slice(w,t.bi);f.push({posA:u[y]??0,posB:p[w]??0,del:this.concat(e),ins:this.concat(r),size:r.join("").length-e.join("").length})}y=t.ai+t.len,w=t.bi+t.len}if(y<l||w<h){const t=i.slice(y),e=a.slice(w);f.push({posA:u[y]??0,posB:p[w]??0,del:this.concat(t),ins:this.concat(e),size:e.join("").length-t.join("").length})}return f.filter(t=>t.del.length>0||t.ins.length>0)}findGroups(){const{contextLines:t}=this.options,e=(t,e,r)=>{const[s,n,i,a]=["delSize","insSize","totalSize","baseLen"].map(e=>t.reduce((t,r)=>t+r[e],0));this.grouped.push({start:e,end:r,delSize:s,insSize:n,totalSize:i,line:t[0].line,entries:t,magnitude:this.magnitude(s,n,a)})};let r=[],s=0,n=0;for(const i of this.entries){const a=Math.max(0,i.line-t),o=i.line+t;!r.length||a<=n+1?(r.length||(s=a),n=Math.max(n,o),r.push(i)):(e(r,s,n),r=[i],s=a,n=o)}r.length&&e(r,s,n)}magnitude(t,e,r){const{maxMagnitudeSymbols:s}=this.options,n=t+e;if(0===n||0===r)return"";const i=Math.min(s,Math.max(Math.round(n/r*s),1)),a=Math.round(e/n*i),o=i-a;return"+".repeat(a)+"-".repeat(o)}output(t){const{mode:e,contextLines:r,groupedLines:s,expandLines:n,showChangeMagnitude:i,lineBreak:a}=this.options,{linesA:o,linesB:c,maxLen:l}=this.text2lines(),h=Math.max(4,l.toString().length),u=(e,r)=>t?`[${r}m${e}`:e,p=e=>t?`${e}`:`-[${e}]`,d=e=>t?`${e}`:`+[${e}]`,g=(t,e,r,s)=>{s&&m(s);for(let s=t;s<=e;s++)f(s,r??s);w.push("")},m=t=>{var e;w.push(`${" ".repeat(h)} ${e=`@@ -${t.line+1},${t.delSize} +${t.line+1},${t.insSize} @@`,u(e,"36")} ${i?(t=>u(t,"33"))(t.magnitude):""}`)},f=(t,e)=>{if(o[t]||c[t]){const s=this.entries.find(e=>e.line===t),n=(t+1).toString().padStart(h," ");s&&e===t?(w.push(`${n} ${r=`- ${y(o[t],s.diffs,"del")}`,u(r,"31")}`),w.push(`${" ".repeat(h)} ${(t=>u(t,"32"))(`+ ${y(c[t],s.diffs,"ins")}`)}`)):w.push(`${n} ${(t=>u(t,"90"))(o[t])}`)}var r},y=(t,r,s)=>{if(!r.length||"line"===e)return t;let n="",i=0;for(const e of r){const r="del"===s?e.posA:e.posB,a="del"===s?e.del:e.ins;a&&(r>i&&(n+=t.slice(i,r)),n+="del"===s?p(a):d(a),i=r+a.length)}return n+t.slice(i)};let w=[""];switch(!0){case n:g(0,l);break;case s:for(const t of this.grouped)g(t.start,t.end,void 0,t);break;default:for(const t of this.entries)g(t.line-r,t.line+r,t.line,t)}return w.join(a)}getStructuredDiff(){return this.entries}getGroupedDiff(){return this.grouped}getASCIIDiff(){return this.output(!1)}getCLIDiff(){return this.output(!0)}}class l{static FNV_PRIME=16777619;static HASH_OFFSET=2166136261;static fnv1a(t){const e=t.length;let r=this.HASH_OFFSET;const s=Math.floor(e/4);for(let e=0;e<s;e++){const s=4*e;r^=t.charCodeAt(s)|t.charCodeAt(s+1)<<8|t.charCodeAt(s+2)<<16|t.charCodeAt(s+3)<<24,r*=this.FNV_PRIME}const n=e%4;if(n>0){const e=4*s;for(let s=0;s<n;s++)r^=t.charCodeAt(e+s),r*=this.FNV_PRIME}return r^=r>>>16,r*=2246822507,r^=r>>>13,r*=3266489909,r^=r>>>16,r>>>0}}class h{static MAX_LEN=2048;static TABLE_SIZE=1e4;table=new Map;key(t,e,r=!1){for(const t of e)if(t.length>h.MAX_LEN)return!1;const s=e.map(t=>l.fnv1a(t));return r&&s.sort(),[t,...s].join("-")}has(t){return this.table.has(t)}get(t){return this.table.get(t)}set(t,e,r=!0){return!(!(this.table.size<h.TABLE_SIZE)||!r&&this.table.has(t)||(this.table.set(t,e),0))}delete(t){this.table.delete(t)}clear(){this.table.clear()}size(){return this.table.size}}class u{static pipeline=new Map;static cache=new h;static getPipeline(t){if(u.pipeline.has(t))return u.pipeline.get(t);const e=[];t.includes("d")&&e.push(t=>t.normalize("NFD")),t.includes("u")&&e.push(t=>t.normalize("NFC")),t.includes("x")&&e.push(t=>t.normalize("NFKC")),t.includes("w")&&e.push(t=>t.replace(/\s+/g," ")),t.includes("t")&&e.push(t=>t.trim()),t.includes("r")&&e.push(t=>t.replace(/(.)\1+/g,"$1")),t.includes("s")&&e.push(t=>t.replace(/[^\p{L}\p{N}\s]/gu,"")),t.includes("k")&&e.push(t=>t.replace(/[^\p{L}]/gu,"")),t.includes("n")&&e.push(t=>t.replace(/\p{N}/gu,"")),t.includes("i")&&e.push(t=>t.toLowerCase());const r=t=>{let r=t;for(const t of e)r=t(r);return r};return u.pipeline.set(t,r),r}static normalize(t,e){if(Array.isArray(t))return t.map(t=>u.normalize(t,e));if(!e||"string"!=typeof e||!t)return t;const r=u.cache.key(e,[t]);if(r&&u.cache.has(r))return u.cache.get(r);const s=u.getPipeline(e)(t);return r&&u.cache.set(r,s),s}static async normalizeAsync(t,e){return await(Array.isArray(t)?Promise.all(t.map(t=>u.normalize(t,e))):Promise.resolve(u.normalize(t,e)))}static clear(){u.pipeline.clear(),u.cache.clear()}}class p{static filters=new Map;static find(t,e){return p.filters.get(t)?.find(t=>t.id===e)}static add(t,e,r,s={}){const{priority:n=10,active:i=!0,overrideable:a=!0}=s,o=p.filters.get(t)??[],c=o.findIndex(t=>t.id===e);if(c>=0){if(!o[c].overrideable)return!1;o.splice(c,1)}return o.push({id:e,fn:r,priority:n,active:i,overrideable:a}),o.sort((t,e)=>t.priority-e.priority),p.filters.set(t,o),!0}static remove(t,e){const r=p.filters.get(t);if(!r)return!1;const s=r.findIndex(t=>t.id===e);return s>=0&&(r.splice(s,1),!0)}static pause(t,e){const r=p.find(t,e);return!!r&&(r.active=!1,!0)}static resume(t,e){const r=p.find(t,e);return!!r&&(r.active=!0,!0)}static list(t,e=!1){const r=p.filters.get(t)??[],s=[];for(const t of r)e&&!t.active||s.push(t.id);return s}static apply(t,e){const r=p.filters.get(t);if(!r||r.every(t=>!t.active))return e;const s=t=>{for(const e of r)e.active&&(t=e.fn(t));return t};return Array.isArray(e)?e.map(s):s(e)}static async applyAsync(t,e){const r=p.filters.get(t);if(!r||r.every(t=>!t.active))return e;const s=async t=>{for(const e of r)e.active&&(t=await Promise.resolve(e.fn(t)));return t};return Array.isArray(e)?Promise.all(e.map(s)):s(e)}static clear(t){t?p.filters.delete(t):p.filters.clear()}}class d{maxSize;buffers=[];pointer=0;constructor(t){this.maxSize=t}acquire(t,e){const r=this.buffers.length;for(let s=0;s<r;s++){const n=(this.pointer+s)%r,i=this.buffers[n];if(i.size>=t)return this.pointer=(n+1)%r,e||i.size===t?i:null}return null}release(t){this.buffers.length<this.maxSize?this.buffers.push(t):(this.buffers[this.pointer]=t,this.pointer=(this.pointer+1)%this.maxSize)}clear(){this.buffers=[],this.pointer=0}}class g{static CONFIG={uint16:{type:"uint16",maxSize:32,maxItemSize:2048,allowOversize:!0},"number[]":{type:"number[]",maxSize:16,maxItemSize:1024,allowOversize:!1},"string[]":{type:"string[]",maxSize:4,maxItemSize:1024,allowOversize:!1},set:{type:"set",maxSize:8,maxItemSize:0,allowOversize:!1},map:{type:"map",maxSize:8,maxItemSize:0,allowOversize:!1}};static POOLS={uint16:new d(32),"number[]":new d(16),"string[]":new d(4),set:new d(8),map:new d(8)};static allocate(t,e){switch(t){case"uint16":return new Uint16Array(e);case"number[]":return new Array(e).fill(0);case"string[]":return new Array(e);case"set":return new Set;case"map":return new Map}}static acquire(t,e){const r=this.CONFIG[t];if(e>r.maxItemSize)return this.allocate(t,e);const s=this.POOLS[t].acquire(e,r.allowOversize);return s?"uint16"===t?s.buffer.subarray(0,e):s.buffer:this.allocate(t,e)}static acquireMany(t,e){return e.map(e=>this.acquire(t,e))}static release(t,e,r){r<=this.CONFIG[t].maxItemSize&&this.POOLS[t].release({buffer:e,size:r})}}class m{static create(t,e){return new m(t,e)}data;key;constructor(t,e){this.data=t,this.key=e}extractFrom(t,e){const r=g.acquire("string[]",t.length);for(let s=0;s<t.length;s++){const n=t[s][e];r[s]="string"==typeof n?n:String(n??"")}return r}extract(){return this.extractFrom(this.data,this.key)}isMetricResult(t){return"object"==typeof t&&null!==t&&"a"in t&&"b"in t&&"res"in t}isCmpStrResult(t){return"object"==typeof t&&null!==t&&"source"in t&&"target"in t&&"match"in t}normalizeResults(t){if(!Array.isArray(t)||0===t.length)return[];const e=t[0];return this.isMetricResult(e)?t:this.isCmpStrResult(e)?t.map(t=>({metric:"unknown",a:t.source,b:t.target,res:t.match,raw:t.raw})):[]}rebuild(t,e,r,s,n){const i=new Array(t.length);let a=0;for(let o=0;o<t.length;o++){const c=t[o];if(s&&0===c.res)continue;let l=c.b&&r.length?r.indexOf(c.b):o;(l<0||l>=e.length)&&(l=o);const h=e[l];i[a++]=n?h:{obj:h,key:this.key,result:{source:c.a,target:r[l]||c.b,match:c.res},...c.raw?{raw:c.raw}:null}}return i.length=a,i}sort(t,e){if(!e||t.length<=1)return t;const r="asc"===e;return t.sort((t,e)=>r?t.res-e.res:e.res-t.res)}performLookup(t,e,r){return this.rebuild(this.sort(this.normalizeResults(t()),r?.sort),this.data,e,r?.removeZero,r?.objectsOnly)}async performLookupAsync(t,e,r){return this.rebuild(this.sort(this.normalizeResults(await t()),r?.sort),this.data,e,r?.removeZero,r?.objectsOnly)}lookup(t,e,r){const s=this.extract();try{return this.performLookup(()=>t(e,s,r),s,r)}finally{g.release("string[]",s,s.length)}}lookupPairs(t,e,r,s){const n=this.extract(),i=this.extractFrom(e,r);try{return this.performLookup(()=>t(n,i,s),n,s)}finally{g.release("string[]",n,n.length),g.release("string[]",i,i.length)}}async lookupAsync(t,e,r){const s=this.extract();try{return await this.performLookupAsync(()=>t(e,s,r),s,r)}finally{g.release("string[]",s,s.length)}}async lookupPairsAsync(t,e,r,s){const n=this.extract(),i=this.extractFrom(e,r);try{return await this.performLookupAsync(()=>t(n,i,s),n,s)}finally{g.release("string[]",n,n.length),g.release("string[]",i,i.length)}}}const f=Object.create(null),y=Object.create(null);function w(t,e){if(t in f||t in y)throw new Error(`Registry <${t}> already exists / overwriting is forbidden`);const r=Object.create(null),s={add(s,n,i=!1){if(!(n.prototype instanceof e))throw new TypeError(`Class must extend <${t}>`);if(!i&&s in r)throw new Error(`Entry <${s}> already exists / use <update=true> to overwrite`);r[s]=n},remove(t){delete r[t]},has:t=>t in r,list:()=>Object.keys(r),get(e){if(!(e in r))throw new Error(`Class <${e}> not registered for <${t}>`);return r[e]}};return f[t]=s,y[t]=(e,...r)=>function(t,e,...r){e=function(t,e){if(!(t in f))throw new ReferenceError(`Registry <${t}> does not exist`);return"string"==typeof e?f[t]?.get(e):e}(t,e);try{return new e(...r)}catch(t){throw new Error(`Cannot instantiate class <${e}>`,{cause:t})}}(t,e,...r),s}const b=a.getInstance();class A{static cache=new h;metric;a;b;origA=[];origB=[];options;symmetric;results;static clear(){this.cache.clear()}static swap(t,e,r,s){return r>s?[e,t,s,r]:[t,e,r,s]}static clamp(t){return Math.max(0,Math.min(1,t))}constructor(t,e,r,s={},n=!1){if(this.metric=t,this.a=Array.isArray(e)?e:[e],this.b=Array.isArray(r)?r:[r],0===this.a.length||0===this.b.length)throw new Error("Inputs <a> and <b> must not be empty");this.options=s,this.symmetric=n}preCompute(t,e,r,s){return t===e?{res:1}:0==r||0==s||r<2&&s<2?{res:0}:void 0}compute(t,e,r,s,n){throw new Error("Method compute() must be overridden in a subclass")}runSingle(t,e){let r=String(this.a[t]),s=r,n=String(this.b[e]),i=n,a=s.length,o=i.length,c=this.preCompute(s,i,a,o);return c||(c=b.run(()=>{const t=A.cache.key(this.metric,[s,i],this.symmetric);return A.cache.get(t||"")??(()=>{this.symmetric&&([s,i,a,o]=A.swap(s,i,a,o));const e=this.compute(s,i,a,o,Math.max(a,o));return t&&A.cache.set(t,e),e})()})),{metric:this.metric,a:this.origA[t]??r,b:this.origB[e]??n,...c}}async runSingleAsync(t,e){return Promise.resolve(this.runSingle(t,e))}runBatch(){const t=[];for(let e=0;e<this.a.length;e++)for(let r=0;r<this.b.length;r++)t.push(this.runSingle(e,r));this.results=t}async runBatchAsync(){const t=[];for(let e=0;e<this.a.length;e++)for(let r=0;r<this.b.length;r++)t.push(await this.runSingleAsync(e,r));this.results=t}runPairwise(){const t=[];for(let e=0;e<this.a.length;e++)t.push(this.runSingle(e,e));this.results=t}async runPairwiseAsync(){const t=[];for(let e=0;e<this.a.length;e++)t.push(await this.runSingleAsync(e,e));this.results=t}setOriginal(t,e){return t&&(this.origA=Array.isArray(t)?t:[t]),e&&(this.origB=Array.isArray(e)?e:[e]),this}isBatch(){return this.a.length>1||this.b.length>1}isSingle(){return!this.isBatch()}isPairwise(t=!1){return!(!this.isBatch()||this.a.length!==this.b.length)||!t&&(()=>{throw new Error("Mode <pairwise> requires arrays of equal length")})()}isSymmetrical(){return this.symmetric}whichMode(t){return t??this.options?.mode??"default"}clear(){this.results=void 0}run(t,e=!0){switch(e&&this.clear(),this.whichMode(t)){case"default":if(this.isSingle()){this.results=this.runSingle(0,0);break}case"batch":this.runBatch();break;case"single":this.results=this.runSingle(0,0);break;case"pairwise":this.isPairwise()&&this.runPairwise();break;default:throw new Error(`Unsupported mode <${t}>`)}}async runAsync(t,e=!0){switch(e&&this.clear(),this.whichMode(t)){case"default":if(this.isSingle()){this.results=await this.runSingleAsync(0,0);break}case"batch":await this.runBatchAsync();break;case"single":this.results=await this.runSingleAsync(0,0);break;case"pairwise":this.isPairwise()&&await this.runPairwiseAsync();break;default:throw new Error(`Unsupported async mode <${t}>`)}}getMetricName(){return this.metric}getResults(){if(void 0===this.results)throw new Error("run() must be called before getResult()");return this.results}}const x=w("metric",A);x.add("cosine",class extends A{constructor(t,e,r={}){super("cosine",t,e,r,!0)}_termFreq(t,e){const r=t.split(e),s=g.acquire("map",r.length);for(const t of r)s.set(t,(s.get(t)||0)+1);return s}compute(t,e){const{delimiter:r=" "}=this.options,s=this._termFreq(t,r),n=this._termFreq(e,r);let i=0,a=0,o=0;for(const[t,e]of s)i+=e*(n.get(t)||0),a+=e*e;for(const t of n.values())o+=t*t;return a=Math.sqrt(a),o=Math.sqrt(o),g.release("map",s,s.size),g.release("map",n,n.size),{res:a&&o?A.clamp(i/(a*o)):0,raw:{dotProduct:i,magnitudeA:a,magnitudeB:o}}}}),x.add("damerau",class extends A{constructor(t,e,r={}){super("damerau",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o,c]=g.acquireMany("uint16",[i,i,i]);for(let t=0;t<=r;t++)o[t]=t;for(let n=1;n<=s;n++){c[0]=n;const s=e.charCodeAt(n-1);for(let i=1;i<=r;i++){const r=t.charCodeAt(i-1),l=r===s?0:1;let h=Math.min(c[i-1]+1,o[i]+1,o[i-1]+l);i>1&&n>1&&r===e.charCodeAt(n-2)&&s===t.charCodeAt(i-2)&&(h=Math.min(h,a[i-2]+l)),c[i]=h}a.set(o),o.set(c)}const l=o[r];return g.release("uint16",a,i),g.release("uint16",o,i),g.release("uint16",c,i),{res:0===n?1:A.clamp(1-l/n),raw:{dist:l,maxLen:n}}}}),x.add("dice",class extends A{constructor(t,e,r={}){super("dice",t,e,r,!0)}_bigrams(t){const e=t.length-1,r=g.acquire("set",e);for(let s=0;s<e;s++)r.add(t.substring(s,s+2));return r}compute(t,e){const r=this._bigrams(t),s=this._bigrams(e);let n=0;for(const t of r)s.has(t)&&n++;const i=r.size,a=s.size,o=i+a;return g.release("set",r,i),g.release("set",s,a),{res:0===o?1:A.clamp(2*n/o),raw:{intersection:n,size:o}}}}),x.add("hamming",class extends A{constructor(t,e,r={}){super("hamming",t,e,r,!0)}compute(t,e,r,s,n){if(r!==s){if(void 0===this.options.pad)throw new Error(`Strings must be of equal length for Hamming Distance, a=${r} and b=${s} given, use option.pad for automatic adjustment`);r<n&&(t=t.padEnd(n,this.options.pad)),s<n&&(e=e.padEnd(n,this.options.pad)),r=s=n}let i=0;for(let r=0;r<t.length;r++)t[r]!==e[r]&&i++;return{res:0===r?1:A.clamp(1-i/r),raw:{dist:i}}}}),x.add("jaccard",class extends A{constructor(t,e,r={}){super("jaccard",t,e,r,!0)}compute(t,e,r,s){const[n,i]=g.acquireMany("set",[r,s]);for(const e of t)n.add(e);for(const t of e)i.add(t);let a=0;for(const t of n)i.has(t)&&a++;const o=n.size+i.size-a;return g.release("set",n,r),g.release("set",i,s),{res:0===o?1:A.clamp(a/o),raw:{intersection:a,union:o}}}}),x.add("jaroWinkler",class extends A{constructor(t,e,r={}){super("jaro-winkler",t,e,r,!0)}compute(t,e,r,s){const n=Math.max(0,Math.floor(s/2)-1),i=g.acquire("uint16",r),a=g.acquire("uint16",s);for(let t=0;t<r;t++)i[t]=0;for(let t=0;t<s;t++)a[t]=0;let o=0;for(let c=0;c<r;c++){const r=Math.max(0,c-n),l=Math.min(c+n+1,s);for(let s=r;s<l;s++)if(!a[s]&&t[c]===e[s]){i[c]=1,a[s]=1,o++;break}}let c=0,l=0,h=0,u=0;if(o>0){let n=0;for(let s=0;s<r;s++)if(i[s]){for(;!a[n];)n++;t[s]!==e[n]&&c++,n++}c/=2,l=(o/r+o/s+(o-c)/o)/3;for(let n=0;n<Math.min(4,r,s)&&t[n]===e[n];n++)h++;u=l+.1*h*(1-l)}return g.release("uint16",i,r),g.release("uint16",a,s),{res:A.clamp(u),raw:{matchWindow:n,matches:o,transpos:c,jaro:l,prefix:h}}}}),x.add("lcs",class extends A{constructor(t,e,r={}){super("lcs",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o]=g.acquireMany("uint16",[i,i]);for(let t=0;t<=r;t++)a[t]=0;for(let n=1;n<=s;n++){o[0]=0;const s=e.charCodeAt(n-1);for(let e=1;e<=r;e++)t.charCodeAt(e-1)===s?o[e]=a[e-1]+1:o[e]=Math.max(a[e],o[e-1]);a.set(o)}const c=a[r];return g.release("uint16",a,i),g.release("uint16",o,i),{res:0===n?1:A.clamp(c/n),raw:{lcs:c,maxLen:n}}}}),x.add("levenshtein",class extends A{constructor(t,e,r={}){super("levenshtein",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o]=g.acquireMany("uint16",[i,i]);for(let t=0;t<=r;t++)a[t]=t;for(let n=1;n<=s;n++){o[0]=n;const s=e.charCodeAt(n-1);for(let e=1;e<=r;e++){const r=t.charCodeAt(e-1)===s?0:1;o[e]=Math.min(o[e-1]+1,a[e]+1,a[e-1]+r)}a.set(o)}const c=a[r];return g.release("uint16",a,i),g.release("uint16",o,i),{res:0===n?1:A.clamp(1-c/n),raw:{dist:c,maxLen:n}}}}),x.add("needlemanWunsch",class extends A{constructor(t,e,r={}){super("needlemanWunsch",t,e,r,!0)}compute(t,e,r,s,n){const{match:i=1,mismatch:a=-1,gap:o=-1}=this.options,c=r+1,[l,h]=g.acquireMany("uint16",[c,c]);l[0]=0;for(let t=1;t<=r;t++)l[t]=l[t-1]+o;for(let n=1;n<=s;n++){h[0]=l[0]+o;const s=e.charCodeAt(n-1);for(let e=1;e<=r;e++){const r=t.charCodeAt(e-1)===s?i:a;h[e]=Math.max(l[e-1]+r,l[e]+o,h[e-1]+o)}l.set(h)}const u=l[r];g.release("uint16",l,c),g.release("uint16",h,c);const p=n*i;return{res:0===p?0:A.clamp(u/p),raw:{score:u,denum:p}}}}),x.add("qGram",class extends A{constructor(t,e,r={}){super("qgram",t,e,r,!0)}_qGrams(t,e){const r=Math.max(0,t.length-e+1),s=g.acquire("set",r);for(let n=0;n<r;n++)s.add(t.slice(n,n+e));return s}compute(t,e){const{q:r=2}=this.options,s=this._qGrams(t,r),n=this._qGrams(e,r);let i=0;for(const t of s)n.has(t)&&i++;const a=s.size,o=n.size,c=Math.max(a,o);return g.release("set",s,a),g.release("set",n,o),{res:0===c?1:A.clamp(i/c),raw:{intersection:i,size:c}}}}),x.add("smithWaterman",class extends A{constructor(t,e,r={}){super("smithWaterman",t,e,r,!0)}compute(t,e,r,s){const{match:n=2,mismatch:i=-1,gap:a=-2}=this.options,o=r+1,[c,l]=g.acquireMany("uint16",[o,o]);for(let t=0;t<=r;t++)c[t]=0;let h=0;for(let o=1;o<=s;o++){l[0]=0;const s=e.charCodeAt(o-1);for(let e=1;e<=r;e++){const r=t.charCodeAt(e-1)===s?n:i;l[e]=Math.max(0,c[e-1]+r,c[e]+a,l[e-1]+a),l[e]>h&&(h=l[e])}c.set(l)}g.release("uint16",c,o),g.release("uint16",l,o);const u=Math.min(r*n,s*n);return{res:0===u?0:A.clamp(h/u),raw:{score:h,denum:u}}}});const v=a.getInstance();class S{static cache=new h;static default;algo;options;map;static clear(){this.cache.clear()}constructor(t,e={}){const r=this.constructor.default??{},n=e.map??r.map;if(!n)throw new Error("No mapping specified for phonetic algorithm");const i=k.get(t,n);if(void 0===i)throw new Error(`Requested mapping <${n}> is not declared`);this.options=s(s(r,i.options??{}),e),this.algo=t,this.map=i}applyPattern(t){const{patterns:e=[]}=this.map;if(!e||!e.length)return t;for(const{pattern:r,replace:s,all:n=!1}of e)t=t[n?"replaceAll":"replace"](r,s);return t}applyRules(t,e,r,s){const{ruleset:n=[]}=this.map;if(!n||!n.length)return;const i=r[e-1]||"",a=r[e-2]||"",o=r[e+1]||"",c=r[e+2]||"";for(const l of n)if((!l.char||l.char===t)&&("start"!==l.position||0===e)&&!("middle"===l.position&&e>0&&e<s)&&("end"!==l.position||e===s)&&(!l.prev||l.prev.includes(i))&&(!l.prevNot||!l.prevNot.includes(i))&&(!l.prev2||l.prev2.includes(a))&&(!l.prev2Not||!l.prev2Not.includes(a))&&(!l.next||l.next.includes(o))&&(!l.nextNot||!l.nextNot.includes(o))&&(!l.next2||l.next2.includes(c))&&(!l.next2Not||!l.next2Not.includes(c))&&(!l.leading||l.leading.includes(r.slice(0,l.leading.length).join("")))&&(!l.trailing||l.trailing.includes(r.slice(-l.trailing.length).join("")))&&(!l.match||l.match.every((t,s)=>r[e+s]===t)))return l.code}encode(t){const{map:e={},ignore:r=[]}=this.map;t=this.applyPattern(t);const s=this.word2Chars(t),n=s.length;let i="",a=null;for(let t=0;t<n;t++){const o=s[t];if(r.includes(o))continue;const c=this.mapChar(o,t,s,n,a,e);if(void 0!==c&&(i+=c,a=c,this.exitEarly(i,t)))break}return this.adjustCode(i,s)}mapChar(t,e,r,s,n,i){const{dedupe:a=!0,fallback:o}=this.options,c=this.applyRules(t,e,r,s)??i[t]??o;return a&&c===n?void 0:c}equalLen(t){const{length:e=-1,pad:r="0"}=this.options;return-1===e?t:(t+r.repeat(e)).slice(0,e)}word2Chars(t){return t.toLowerCase().split("")}exitEarly(t,e){const{length:r=-1}=this.options;return r>0&&t.length>=r}adjustCode(t,e){return t}loop(t){const e=[];for(const r of t){const t=S.cache.key(this.algo,[r]),s=S.cache.get(t||"")??(()=>{const e=this.encode(r);return t&&S.cache.set(t,e),e})();s&&s.length&&e.push(this.equalLen(s))}return e}async loopAsync(t){const e=[];for(const r of t){const t=await Promise.resolve(this.encode(r));t&&t.length&&e.push(this.equalLen(t))}return e}getAlgoName(){return this.algo}getIndex(t){const{delimiter:e=" "}=this.options;return v.run(()=>this.loop(t.split(e).filter(Boolean)).filter(Boolean))}async getIndexAsync(t){const{delimiter:e=" "}=this.options;return(await v.runAsync(async()=>await this.loopAsync(t.split(e).filter(Boolean)))).filter(Boolean)}}const z=w("phonetic",S),k=(()=>{const t=Object.create(null),e=e=>t[e]||=Object.create(null);return{add(t,r,s,n=!1){const i=e(t);if(!n&&r in i)throw new Error(`Entry <${r}> already exists / use <update=true> to overwrite`);i[r]=s},remove(t,r){delete e(t)[r]},has:(t,r)=>r in e(t),get:(t,r)=>e(t)[r],list:t=>Object.keys(e(t))}})();z.add("caverphone",class extends S{static default={map:"en2",delimiter:" ",length:-1,pad:"",dedupe:!1};constructor(t={}){super("caverphone",t)}encode(t){return t=t.replace(/[^A-Z]/gi,"").toLowerCase(),super.encode(t)}mapChar(t){return t}adjustCode(t){return t.toUpperCase()}}),k.add("caverphone","en1",{options:{length:6,pad:"1"},map:{},patterns:[{pattern:/^(c|r|t|en)ough/,replace:"$1ou2f"},{pattern:/^gn/,replace:"2n"},{pattern:/mb$/,replace:"m2"},{pattern:/cq/g,replace:"2q"},{pattern:/c(e|i|y)/g,replace:"s$1"},{pattern:/tch/g,replace:"2ch"},{pattern:/[cqx]/g,replace:"k"},{pattern:/v/g,replace:"f"},{pattern:/dg/g,replace:"2g"},{pattern:/ti(a|o)/g,replace:"si$1"},{pattern:/d/g,replace:"t"},{pattern:/ph/g,replace:"fh"},{pattern:/b/g,replace:"p"},{pattern:/sh/g,replace:"s2"},{pattern:/z/g,replace:"s"},{pattern:/^[aeiou]/,replace:"A"},{pattern:/[aeiou]/g,replace:"3"},{pattern:/3gh3/g,replace:"3kh3"},{pattern:/gh/g,replace:"22"},{pattern:/g/g,replace:"k"},{pattern:/s+/g,replace:"S"},{pattern:/t+/g,replace:"T"},{pattern:/p+/g,replace:"P"},{pattern:/k+/g,replace:"K"},{pattern:/f+/g,replace:"F"},{pattern:/m+/g,replace:"M"},{pattern:/n+/g,replace:"N"},{pattern:/j/g,replace:"y"},{pattern:/l3/g,replace:"L3"},{pattern:/r3/g,replace:"R3"},{pattern:/w3/g,replace:"W3"},{pattern:/y3/g,replace:"Y3"},{pattern:/ly/g,replace:"Ly"},{pattern:/ry/g,replace:"Ry"},{pattern:/wy/g,replace:"Wy"},{pattern:/wh3/g,replace:"Wh3"},{pattern:/why/g,replace:"Why"},{pattern:/^h/,replace:"A"},{pattern:/[hlrwy23]/g,replace:""}]}),k.add("caverphone","en2",{options:{length:10,pad:"1"},map:{},patterns:[{pattern:/e$/,replace:""},{pattern:/^(c|r|t|en|tr)ough/,replace:"$1ou2f"},{pattern:/^gn/,replace:"2n"},{pattern:/mb$/,replace:"m2"},{pattern:/cq/g,replace:"2q"},{pattern:/c(e|i|y)/g,replace:"s$1"},{pattern:/tch/g,replace:"2ch"},{pattern:/[cqx]/g,replace:"k"},{pattern:/v/g,replace:"f"},{pattern:/dg/g,replace:"2g"},{pattern:/ti(a|o)/g,replace:"si$1"},{pattern:/d/g,replace:"t"},{pattern:/ph/g,replace:"fh"},{pattern:/b/g,replace:"p"},{pattern:/sh/g,replace:"s2"},{pattern:/z/g,replace:"s"},{pattern:/^[aeiou]/,replace:"A"},{pattern:/[aeiou]/g,replace:"3"},{pattern:/j/g,replace:"y"},{pattern:/^y3/,replace:"Y3"},{pattern:/^y/,replace:"A"},{pattern:/y/g,replace:"3"},{pattern:/3gh3/g,replace:"3kh3"},{pattern:/gh/g,replace:"22"},{pattern:/g/g,replace:"k"},{pattern:/s+/g,replace:"S"},{pattern:/t+/g,replace:"T"},{pattern:/p+/g,replace:"P"},{pattern:/k+/g,replace:"K"},{pattern:/f+/g,replace:"F"},{pattern:/m+/g,replace:"M"},{pattern:/n+/g,replace:"N"},{pattern:/l3/g,replace:"L3"},{pattern:/r3/g,replace:"R3"},{pattern:/w3/g,replace:"W3"},{pattern:/wh3/g,replace:"Wh3"},{pattern:/[lrw]$/,replace:"3"},{pattern:/^h/,replace:"A"},{pattern:/3$/,replace:"A"},{pattern:/[hlrw23]/g,replace:""}]}),z.add("cologne",class extends S{static default={map:"default",delimiter:" ",length:-1,dedupe:!0};constructor(t={}){super("cologne",t)}adjustCode(t){return t.slice(0,1)+t.slice(1).replaceAll("0","")}}),k.add("cologne","default",{map:{a:"0","ä":"0",e:"0",i:"0",j:"0",o:"0","ö":"0",u:"0","ü":"0",y:"0",b:"1",p:"1",d:"2",t:"2",f:"3",v:"3",w:"3",g:"4",k:"4",q:"4",l:"5",m:"6",n:"6",r:"7",c:"8",s:"8","ß":"8",z:"8",x:"48"},ignore:["h"],ruleset:[{char:"p",next:["h"],code:"3"},{char:"c",position:"start",next:["a","h","k","l","o","q","r","u","x"],code:"4"},{char:"c",next:["a","h","k","o","q","u","x"],prevNot:["s","z"],code:"4"},{char:"d",next:["c","s","z"],code:"8"},{char:"t",next:["c","s","z"],code:"8"},{char:"x",prev:["c","k","q"],code:"8"}]}),z.add("metaphone",class extends S{static default={map:"en90",delimiter:" ",length:-1,pad:"",dedupe:!1};constructor(t={}){super("metaphone",t)}encode(t){return t=t.replace(/([A-BD-Z])\1+/gi,(t,e)=>"C"===e?t:e),super.encode(t)}adjustCode(t){return t.slice(0,1)+t.slice(1).replace(/[AEIOU]/g,"")}}),k.add("metaphone","en90",{map:{a:"A",b:"B",c:"K",d:"T",e:"E",f:"F",g:"K",h:"H",i:"I",j:"J",k:"K",l:"L",m:"M",n:"N",o:"O",p:"P",q:"K",r:"R",s:"S",t:"T",u:"U",v:"F",w:"W",x:"KS",y:"Y",z:"S"},ruleset:[{char:"a",position:"start",next:["e"],code:""},{char:"g",position:"start",next:["n"],code:""},{char:"k",position:"start",next:["n"],code:""},{char:"p",position:"start",next:["n"],code:""},{char:"w",position:"start",next:["r"],code:""},{char:"b",position:"end",prev:["m"],code:""},{char:"c",next:["h"],prevNot:["s"],code:"X"},{char:"c",next:["i"],next2:["a"],code:"X"},{char:"c",next:["e","i","y"],code:"S"},{char:"d",next:["g"],next2:["e","i","y"],code:"J"},{char:"g",next:["h"],next2Not:["","a","e","i","o","u"],code:""},{char:"g",trailing:"n",code:""},{char:"g",trailing:"ned",code:""},{char:"g",next:["e","i","y"],prevNot:["g"],code:"J"},{char:"h",prev:["a","e","i","o","u"],nextNot:["a","e","i","o","u"],code:""},{char:"h",prev:["c","g","p","s","t"],code:""},{char:"k",prev:["c"],code:""},{char:"p",next:["h"],code:"F"},{char:"s",next:["h"],code:"X"},{char:"s",next:["i"],next2:["a","o"],code:"X"},{char:"t",next:["i"],next2:["a","o"],code:"X"},{char:"t",next:["h"],code:"0"},{char:"t",next:["c"],next2:["h"],code:""},{char:"w",nextNot:["a","e","i","o","u"],code:""},{char:"h",leading:"w",code:""},{char:"x",position:"start",code:"S"},{char:"y",nextNot:["a","e","i","o","u"],code:""}]}),z.add("soundex",class extends S{static default={map:"en",delimiter:" ",length:4,pad:"0",dedupe:!0};constructor(t={}){super("soundex",t)}adjustCode(t,e){return e[0].toUpperCase()+t.slice(1).replaceAll("0","")}}),k.add("soundex","en",{map:{a:"0",e:"0",h:"0",i:"0",o:"0",u:"0",w:"0",y:"0",b:"1",f:"1",p:"1",v:"1",c:"2",g:"2",j:"2",k:"2",q:"2",s:"2",x:"2",z:"2",d:"3",t:"3",l:"4",m:"5",n:"5",r:"6"}}),k.add("soundex","de",{map:{a:"0","ä":"0",e:"0",h:"0",i:"0",j:"0",o:"0","ö":"0",u:"0","ü":"0",y:"0",b:"1",f:"1",p:"1",v:"1",w:"1",c:"2",g:"2",k:"2",q:"2",s:"2","ß":"2",x:"2",z:"2",d:"3",t:"3",l:"4",m:"5",n:"5",r:"6"},ruleset:[{char:"c",next:["h"],code:"7"}]});const C=a.getInstance();class M{static filter={add:p.add,remove:p.remove,pause:p.pause,resume:p.resume,list:p.list,clear:p.clear};static metric={add:x.add,remove:x.remove,has:x.has,list:x.list};static phonetic={add:z.add,remove:z.remove,has:z.has,list:z.list,map:{add:k.add,remove:k.remove,has:k.has,list:k.list}};static profiler=C.services;static clearCache={normalizer:u.clear,metric:A.clear,phonetic:S.clear};static analyze(t){return new o(t)}static diff(t,e,r){return new c(t,e,r)}static create(t){return new M(t)}options=Object.create(null);constructor(t){t&&("string"==typeof t?this.setSerializedOptions(t):this.setOptions(t))}assert(t,e){switch(t){case"metric":if(!M.metric.has(e))throw new Error("CmpStr <metric> must be set, call .setMetric(), use CmpStr.metric.list() for available metrics");break;case"phonetic":if(!M.phonetic.has(e))throw new Error("CmpStr <phonetic> must be set, call .setPhonetic(), use CmpStr.phonetic.list() for available phonetic algorithms");break;default:throw new Error(`Cmpstr condition <${t}> unknown`)}}assertMany(...t){for(const[e,r]of t)this.assert(e,r)}resolveOptions(t){return s({...this.options??Object.create(null)},t)}normalize(t,e){return u.normalize(t,e??this.options.flags??"")}filter(t,e){return p.apply(e,t)}prepare(t,e){const{flags:r,processors:s}=e??this.options;return r?.length&&(t=this.normalize(t,r)),t=this.filter(t,"input"),s?.phonetic&&(t=this.index(t,s.phonetic)),t}postProcess(t,e){return e?.removeZero&&Array.isArray(t)&&(t=t.filter(t=>t.res>0)),t}index(t,{algo:e,opt:r}){this.assert("phonetic",e);const s=y.phonetic(e,r),n=r?.delimiter??" ";return Array.isArray(t)?t.map(t=>s.getIndex(t).join(n)):s.getIndex(t).join(n)}structured(t,e){return m.create(t,e)}compute(t,e,r,s,n,i){const a=this.resolveOptions(r);this.assert("metric",a.metric);const o=i?t:this.prepare(t,a),c=i?e:this.prepare(e,a);if(a.safeEmpty&&(Array.isArray(o)&&0===o.length||Array.isArray(c)&&0===c.length||""===o||""===c))return[];const l=y.metric(a.metric,o,c,a.opt);"prep"!==a.output&&l.setOriginal(t,e),l.run(s);const h=this.postProcess(l.getResults(),a);return this.output(h,n??a.raw)}output(t,e){return e??this.options.raw?t:Array.isArray(t)?t.map(t=>({source:t.a,target:t.b,match:t.res})):{source:t.a,target:t.b,match:t.res}}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}reset(){for(const t in this.options)delete this.options[t];return this}setOptions(t){return this.options=t,this}mergeOptions(t){return s(this.options,t),this}setSerializedOptions(t){return this.options=JSON.parse(t),this}setOption(t,e){return r(this.options,t,e),this}rmvOption(t){return n(this.options,t),this}setRaw(t){return this.setOption("raw",t)}setMetric(t){return this.setOption("metric",t)}setFlags(t){return this.setOption("flags",t)}rmvFlags(){return this.rmvOption("flags")}setProcessors(t){return this.setOption("processors",t)}rmvProcessors(){return this.rmvOption("processors")}getOptions(){return this.options}getSerializedOptions(){return JSON.stringify(this.options)}getOption(t){return e(this.options,t)}test(t,e,r){return this.compute(t,e,r,"single")}compare(t,e,r){return this.compute(t,e,r,"single",!0).res}batchTest(t,e,r){return this.compute(t,e,r,"batch")}batchSorted(t,e,r="desc",s){return this.output(this.compute(t,e,s,"batch",!0).sort((t,e)=>"asc"===r?t.res-e.res:e.res-t.res),s?.raw??this.options.raw)}pairs(t,e,r){return this.compute(t,e,r,"pairwise")}match(t,e,r,s){return this.output(this.compute(t,e,s,"batch",!0).filter(t=>t.res>=r).sort((t,e)=>e.res-t.res),s?.raw??this.options.raw)}closest(t,e,r=1,s){return this.batchSorted(t,e,"desc",s).slice(0,r)}furthest(t,e,r=1,s){return this.batchSorted(t,e,"asc",s).slice(0,r)}search(t,e,r,s){const n=this.resolveOptions({flags:r,processors:s}),i=this.prepare(t,n),a=this.prepare(e,n);return e.filter((t,e)=>a[e].includes(i))}matrix(t,e){return(t=this.prepare(t,this.resolveOptions(e))).map(e=>this.compute(e,t,void 0,"batch",!0,!0).map(t=>t.res??0))}phoneticIndex(t,e,r){const{algo:s,opt:n}=this.options.processors?.phonetic??{};return this.index(t,{algo:e??s,opt:r??n})}structuredLookup(t,e,r,s){return this.structured(e,r).lookup((t,e,r)=>this.batchTest(t,e,r),t,s)}structuredMatch(t,e,r,s,n){return this.structured(e,r).lookup((t,e,r)=>this.match(t,e,s,r),t,{...n,sort:"desc"})}structuredClosest(t,e,r,s=1,n){return this.structured(e,r).lookup((t,e,r)=>this.closest(t,e,s,r),t,{...n,sort:"desc"})}structuredFurthest(t,e,r,s=1,n){return this.structured(e,r).lookup((t,e,r)=>this.furthest(t,e,s,r),t,{...n,sort:"asc"})}structuredPairs(t,e,r,s,n){return this.structured(t,e).lookupPairs((t,e,r)=>this.pairs(t,e,r),r,s,n)}}class O extends M{static create(t){return new O(t)}constructor(t){super(t)}async normalizeAsync(t,e){return u.normalizeAsync(t,e??this.options.flags??"")}async filterAsync(t,e){return p.applyAsync(e,t)}async prepareAsync(t,e){const{flags:r,processors:s}=e??this.options;return r?.length&&(t=await this.normalizeAsync(t,r)),t=await this.filterAsync(t,"input"),s?.phonetic&&(t=await this.indexAsync(t,s.phonetic)),t}async indexAsync(t,{algo:e,opt:r}){this.assert("phonetic",e);const s=y.phonetic(e,r),n=r?.delimiter??" ";return Array.isArray(t)?Promise.all(t.map(t=>s.getIndexAsync(t).then(t=>t.join(n)))):s.getIndexAsync(t).then(t=>t.join(n))}async computeAsync(t,e,r,s,n,i){const a=this.resolveOptions(r);this.assert("metric",a.metric);const o=i?t:await this.prepareAsync(t,a),c=i?e:await this.prepareAsync(e,a);if(a.safeEmpty&&(Array.isArray(o)&&0===o.length||Array.isArray(c)&&0===c.length||""===o||""===c))return[];const l=y.metric(a.metric,o,c,a.opt);"prep"!==a.output&&l.setOriginal(t,e),await l.runAsync(s);const h=this.postProcess(l.getResults(),a);return this.output(h,n??a.raw)}async testAsync(t,e,r){return this.computeAsync(t,e,r,"single")}async compareAsync(t,e,r){return(await this.computeAsync(t,e,r,"single",!0)).res}async batchTestAsync(t,e,r){return this.computeAsync(t,e,r,"batch")}async batchSortedAsync(t,e,r="desc",s){const n=await this.computeAsync(t,e,s,"batch",!0);return this.output(n.sort((t,e)=>"asc"===r?t.res-e.res:e.res-t.res),s?.raw??this.options.raw)}async pairsAsync(t,e,r){return this.computeAsync(t,e,r,"pairwise")}async matchAsync(t,e,r,s){const n=await this.computeAsync(t,e,s,"batch",!0);return this.output(n.filter(t=>t.res>=r).sort((t,e)=>e.res-t.res),s?.raw??this.options.raw)}async closestAsync(t,e,r=1,s){return(await this.batchSortedAsync(t,e,"desc",s)).slice(0,r)}async furthestAsync(t,e,r=1,s){return(await this.batchSortedAsync(t,e,"asc",s)).slice(0,r)}async searchAsync(t,e,r,s){const n=this.resolveOptions({flags:r,processors:s}),i=await this.prepareAsync(t,n),a=await this.prepareAsync(e,n);return e.filter((t,e)=>a[e].includes(i))}async matrixAsync(t,e){return t=await this.prepareAsync(t,this.resolveOptions(e)),Promise.all(t.map(async e=>await this.computeAsync(e,t,void 0,"batch",!0,!0).then(t=>t.map(t=>t.res??0))))}async phoneticIndexAsync(t,e,r){const{algo:s,opt:n}=this.options.processors?.phonetic??{};return this.indexAsync(t,{algo:e??s,opt:r??n})}async structuredLookupAsync(t,e,r,s){return await this.structured(e,r).lookupAsync((t,e,r)=>this.batchTestAsync(t,e,r),t,s)}async structuredMatchAsync(t,e,r,s,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.matchAsync(t,e,s,r),t,{...n,sort:"desc"})}async structuredClosestAsync(t,e,r,s=1,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.closestAsync(t,e,s,r),t,{...n,sort:"desc"})}async structuredFurthestAsync(t,e,r,s=1,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.furthestAsync(t,e,s,r),t,{...n,sort:"asc"})}async structuredPairsAsync(t,e,r,s,n){return await this.structured(t,e).lookupPairsAsync((t,e,r)=>this.pairsAsync(t,e,r),r,s,n)}}export{M as CmpStr,O as CmpStrAsync,i as DeepMerge,c as DiffChecker,p as Filter,h as HashTable,A as Metric,x as MetricRegistry,u as Normalizer,S as Phonetic,k as PhoneticMappingRegistry,z as PhoneticRegistry,g as Pool,a as Profiler,m as StructuredData,o as TextAnalyzer};
7
+ const t=t=>t.replace(/\[(\d+)]/g,".$1").split(".").map(t=>/^\d+$/.test(t)?+t:t);function e(e,r,s){return t(r).reduce((t,e)=>t?.[e]??s,e)}function r(e,s,n){if(""===s)return n;const[i,...a]=t(s);if(void 0!==e&&("object"!=typeof e||null===e))throw Error(`Cannot set property <${i}> of <${JSON.stringify(e)}>`);return Object.assign(e??("number"==typeof i?[]:Object.create(null)),{[i]:r(e?.[i],a.join("."),n)})}function s(t=Object.create(null),e=Object.create(null),r=!1){return Object.keys(e).forEach(n=>{const i=e[n];(r||void 0!==i)&&"__proto__"!==n&&"constructor"!==n&&(t[n]="object"!=typeof i||Array.isArray(i)?i:s("object"!=typeof t[n]||Array.isArray(t[n])?Object.create(null):t[n],i))}),t}function n(e,r,s=!1){const n=(t,e,r=0)=>{const i=e[r];if(!t||"object"!=typeof t)return!1;if(r===e.length-1)return delete t[i];if(!n(t[i],e,r+1))return!1;if(!s){const e=t[i];"object"==typeof e&&(Array.isArray(e)&&e.every(t=>null==t)||!Array.isArray(e)&&0===Object.keys(e).length)&&delete t[i]}return!0};return n(e,t(r)),e}var i=Object.freeze({__proto__:null,get:e,has:function(e,r){return void 0!==t(r).reduce((t,e)=>t&&e in t?t[e]:void 0,e)},merge:s,rmv:n,set:r});class a{static ENV;static instance;store=new Set;totalTime=0;totalMem=0;active;static detectEnv(){"undefined"!=typeof process?a.ENV="nodejs":"undefined"!=typeof performance?a.ENV="browser":a.ENV="unknown"}static getInstance(t){return a.ENV||a.detectEnv(),a.instance||(a.instance=new a(t)),a.instance}constructor(t){this.active=t??!1}now(){switch(a.ENV){case"nodejs":return Number(process.hrtime.bigint())/1e6;case"browser":return performance.now();default:return Date.now()}}mem(){switch(a.ENV){case"nodejs":return process.memoryUsage().heapUsed;case"browser":return performance.memory?.usedJSHeapSize??0;default:return 0}}enable(){this.active=!0}disable(){this.active=!1}clear(){this.store.clear(),this.totalTime=0,this.totalMem=0}run(t,e={}){if(!this.active)return t();const r=this.now(),s=this.mem(),n=t(),i=this.now()-r,a=this.mem()-s;return this.store.add({time:i,mem:a,res:n,meta:e}),this.totalTime+=i,this.totalMem+=a,n}async runAsync(t,e={}){if(!this.active)return await t();const r=this.now(),s=this.mem(),n=await t(),i=this.now()-r,a=this.mem()-s;return this.store.add({time:i,mem:a,res:n,meta:e}),this.totalTime+=i,this.totalMem+=a,n}getAll(){return[...this.store]}getLast(){return this.getAll().pop()}getTotal(){return{time:this.totalTime,mem:this.totalMem}}services={enable:this.enable.bind(this),disable:this.disable.bind(this),clear:this.clear.bind(this),report:this.getAll.bind(this),last:this.getLast.bind(this),total:this.getTotal.bind(this)}}class o{text;words=[];sentences=[];charFrequency=new Map;wordHistogram=new Map;syllableCache=new Map;constructor(t){this.text=t.trim(),this.tokenize(),this.computeFrequencies()}tokenize(){this.words=[],this.sentences=[];const t=this.text,e=/\p{L}+/gu;let r;for(;null!==(r=e.exec(t));)this.words.push(r[0].toLowerCase());this.sentences=t.split(/(?<=[.!?])\s+/).filter(Boolean)}computeFrequencies(){for(const t of this.text)this.charFrequency.set(t,(this.charFrequency.get(t)??0)+1);for(const t of this.words)this.wordHistogram.set(t,(this.wordHistogram.get(t)??0)+1)}estimateSyllables(t){if(this.syllableCache.has(t))return this.syllableCache.get(t);const e=t.toLowerCase().replace(/[^a-zäöüß]/g,"").match(/[aeiouyäöü]+/g),r=e?e.length:1;return this.syllableCache.set(t,r),r}getLength(){return this.text.length}getWordCount(){return this.words.length}getSentenceCount(){return this.sentences.length}getAvgWordLength(){let t=0;for(const e of this.words)t+=e.length;return this.words.length?t/this.words.length:0}getAvgSentenceLength(){return this.sentences.length?this.words.length/this.sentences.length:0}getWordHistogram(){return Object.fromEntries(this.wordHistogram)}getMostCommonWords(t=5){return[...this.wordHistogram.entries()].sort((t,e)=>e[1]-t[1]).slice(0,t).map(t=>t[0])}getHapaxLegomena(){return[...this.wordHistogram.entries()].filter(([,t])=>1===t).map(t=>t[0])}hasNumbers(){return/\d/.test(this.text)}getUpperCaseRatio(){let t=0,e=0;for(let r=0,s=this.text.length;r<s;r++){const s=this.text[r];/[A-Za-zÄÖÜäöüß]/.test(s)&&(e++,/[A-ZÄÖÜ]/.test(s)&&t++)}return e?t/e:0}getCharFrequency(){return Object.fromEntries(this.charFrequency)}getUnicodeStats(){const t={};for(const[e,r]of this.charFrequency){const s=e.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase();t[s]=(t[s]??0)+r}return t}getLongWordRatio(t=7){let e=0;for(const r of this.words)r.length>=t&&e++;return this.words.length?e/this.words.length:0}getShortWordRatio(t=3){let e=0;for(const r of this.words)r.length<=t&&e++;return this.words.length?e/this.words.length:0}getSyllablesCount(){let t=0;for(const e of this.words)t+=this.estimateSyllables(e);return t}getMonosyllabicWordCount(){let t=0;for(const e of this.words)1===this.estimateSyllables(e)&&t++;return t}getMinSyllablesWordCount(t){let e=0;for(const r of this.words)this.estimateSyllables(r)>=t&&e++;return e}getMaxSyllablesWordCount(t){let e=0;for(const r of this.words)this.estimateSyllables(r)<=t&&e++;return e}getHonoresR(){return 100*Math.log(this.words.length)/(1-this.getHapaxLegomena().length/(this.wordHistogram.size??1))}getReadingTime(t=200){return Math.max(1,this.words.length/(t??1))}getReadabilityScore(t="flesch"){const e=this.words.length||1,r=e/(this.sentences.length||1),s=(this.getSyllablesCount()||1)/e;switch(t){case"flesch":return 206.835-1.015*r-84.6*s;case"fleschde":return 180-r-58.5*s;case"kincaid":return.39*r+11.8*s-15.59}}getLIXScore(){const t=this.words.length||1;return t/(this.sentences.length||1)+this.getLongWordRatio()*t/t*100}getWSTFScore(){const t=this.words.length||1,e=this.getMinSyllablesWordCount(3)/t*100,r=this.getAvgSentenceLength(),s=100*this.getLongWordRatio();return[.1935*e+.1672*r+.1297*s-this.getMonosyllabicWordCount()/t*100*.0327-.875,.2007*e+.1682*r+.1373*s-2.779,.2963*e+.1905*r-1.1144,.2744*e+.2656*r-1.693]}}class c{a;b;options;entries=[];grouped=[];diffRun=!1;constructor(t,e,r={}){this.a=t,this.b=e,this.options={mode:"word",caseInsensitive:!1,contextLines:1,groupedLines:!0,expandLines:!1,showChangeMagnitude:!0,maxMagnitudeSymbols:5,lineBreak:"\n",...r},this.computeDiff()}text2lines(){const t=this.a.trim().split(/\r?\n/),e=this.b.trim().split(/\r?\n/);return{linesA:t,linesB:e,maxLen:Math.max(t.length,e.length)}}tokenize(t){const{mode:e}=this.options;switch(e){case"line":return[t];case"word":return t.split(/\s+/)}}concat(t){const{mode:e}=this.options;return t.join("word"===e?" ":"")}computeDiff(){if(!this.diffRun){const{linesA:t,linesB:e,maxLen:r}=this.text2lines();for(let s=0;s<r;s++){const r=t[s]||"",n=e[s]||"";this.lineDiff(r,n,s)}this.findGroups(),this.diffRun=!0}}lineDiff(t,e,r){const{mode:s,caseInsensitive:n}=this.options,i=Math.max(t.length,e.length);let a=t,o=e;n&&(a=t.toLowerCase(),o=e.toLowerCase());let c=[],l=0,h=0;if("line"===s)a!==o&&(c.push({posA:0,posB:0,del:t,ins:e,size:e.length-t.length}),l=t.length,h=e.length);else{c=this.preciseDiff(t,a,e,o);for(const t of c)l+=t.del.length,h+=t.ins.length}c.length&&this.entries.push({line:r,diffs:c,delSize:l,insSize:h,baseLen:i,totalSize:h-l,magnitude:this.magnitude(l,h,i)})}preciseDiff(t,e,r,s){const n=t=>t.reduce((e,r,s)=>(e.push(s?e[s-1]+t[s-1].length+1:0),e),[]),i=this.tokenize(t),a=this.tokenize(r),o=this.tokenize(e),c=this.tokenize(s),l=o.length,h=c.length,u=n(i),p=n(a),d=[];let g=0,m=0;for(;g<l&&m<h;)if(o[g]===c[m]){let t=1;for(;g+t<l&&m+t<h&&o[g+t]===c[m+t];)t++;d.push({ai:g,bi:m,len:t}),g+=t,m+=t}else{let t=!1;for(let e=1;e<=3&&!t;e++)g+e<l&&o[g+e]===c[m]?(d.push({ai:g+e,bi:m,len:1}),g+=e+1,m+=1,t=!0):m+e<h&&o[g]===c[m+e]&&(d.push({ai:g,bi:m+e,len:1}),g+=1,m+=e+1,t=!0);t||(g++,m++)}const f=[];let y=0,w=0;for(const t of d){if(y<t.ai||w<t.bi){const e=i.slice(y,t.ai),r=a.slice(w,t.bi);f.push({posA:u[y]??0,posB:p[w]??0,del:this.concat(e),ins:this.concat(r),size:r.join("").length-e.join("").length})}y=t.ai+t.len,w=t.bi+t.len}if(y<l||w<h){const t=i.slice(y),e=a.slice(w);f.push({posA:u[y]??0,posB:p[w]??0,del:this.concat(t),ins:this.concat(e),size:e.join("").length-t.join("").length})}return f.filter(t=>t.del.length>0||t.ins.length>0)}findGroups(){const{contextLines:t}=this.options,e=(t,e,r)=>{const[s,n,i,a]=["delSize","insSize","totalSize","baseLen"].map(e=>t.reduce((t,r)=>t+r[e],0));this.grouped.push({start:e,end:r,delSize:s,insSize:n,totalSize:i,line:t[0].line,entries:t,magnitude:this.magnitude(s,n,a)})};let r=[],s=0,n=0;for(const i of this.entries){const a=Math.max(0,i.line-t),o=i.line+t;!r.length||a<=n+1?(r.length||(s=a),n=Math.max(n,o),r.push(i)):(e(r,s,n),r=[i],s=a,n=o)}r.length&&e(r,s,n)}magnitude(t,e,r){const{maxMagnitudeSymbols:s}=this.options,n=t+e;if(0===n||0===r)return"";const i=Math.min(s,Math.max(Math.round(n/r*s),1)),a=Math.round(e/n*i),o=i-a;return"+".repeat(a)+"-".repeat(o)}output(t){const{mode:e,contextLines:r,groupedLines:s,expandLines:n,showChangeMagnitude:i,lineBreak:a}=this.options,{linesA:o,linesB:c,maxLen:l}=this.text2lines(),h=Math.max(4,l.toString().length),u=(e,r)=>t?`[${r}m${e}`:e,p=e=>t?`${e}`:`-[${e}]`,d=e=>t?`${e}`:`+[${e}]`,g=(t,e,r,s)=>{s&&m(s);for(let s=t;s<=e;s++)f(s,r??s);w.push("")},m=t=>{var e;w.push(`${" ".repeat(h)} ${e=`@@ -${t.line+1},${t.delSize} +${t.line+1},${t.insSize} @@`,u(e,"36")} ${i?(t=>u(t,"33"))(t.magnitude):""}`)},f=(t,e)=>{if(o[t]||c[t]){const s=this.entries.find(e=>e.line===t),n=(t+1).toString().padStart(h," ");s&&e===t?(w.push(`${n} ${r=`- ${y(o[t],s.diffs,"del")}`,u(r,"31")}`),w.push(`${" ".repeat(h)} ${(t=>u(t,"32"))(`+ ${y(c[t],s.diffs,"ins")}`)}`)):w.push(`${n} ${(t=>u(t,"90"))(o[t])}`)}var r},y=(t,r,s)=>{if(!r.length||"line"===e)return t;let n="",i=0;for(const e of r){const r="del"===s?e.posA:e.posB,a="del"===s?e.del:e.ins;a&&(r>i&&(n+=t.slice(i,r)),n+="del"===s?p(a):d(a),i=r+a.length)}return n+t.slice(i)};let w=[""];switch(!0){case n:g(0,l);break;case s:for(const t of this.grouped)g(t.start,t.end,void 0,t);break;default:for(const t of this.entries)g(t.line-r,t.line+r,t.line,t)}return w.join(a)}getStructuredDiff(){return this.entries}getGroupedDiff(){return this.grouped}getASCIIDiff(){return this.output(!1)}getCLIDiff(){return this.output(!0)}}class l{static FNV_PRIME=16777619;static HASH_OFFSET=2166136261;static fnv1a(t){const e=t.length;let r=this.HASH_OFFSET;const s=Math.floor(e/4);for(let e=0;e<s;e++){const s=4*e;r^=t.charCodeAt(s)|t.charCodeAt(s+1)<<8|t.charCodeAt(s+2)<<16|t.charCodeAt(s+3)<<24,r*=this.FNV_PRIME}const n=e%4;if(n>0){const e=4*s;for(let s=0;s<n;s++)r^=t.charCodeAt(e+s),r*=this.FNV_PRIME}return r^=r>>>16,r*=2246822507,r^=r>>>13,r*=3266489909,r^=r>>>16,r>>>0}}class h{static MAX_LEN=2048;static TABLE_SIZE=1e4;table=new Map;key(t,e,r=!1){for(const t of e)if(t.length>h.MAX_LEN)return!1;const s=e.map(t=>l.fnv1a(t));return r&&s.sort(),[t,...s].join("-")}has(t){return this.table.has(t)}get(t){return this.table.get(t)}set(t,e,r=!0){return!(!(this.table.size<h.TABLE_SIZE)||!r&&this.table.has(t)||(this.table.set(t,e),0))}delete(t){this.table.delete(t)}clear(){this.table.clear()}size(){return this.table.size}}class u{static pipeline=new Map;static cache=new h;static getPipeline(t){if(u.pipeline.has(t))return u.pipeline.get(t);const e=[];t.includes("d")&&e.push(t=>t.normalize("NFD")),t.includes("u")&&e.push(t=>t.normalize("NFC")),t.includes("x")&&e.push(t=>t.normalize("NFKC")),t.includes("w")&&e.push(t=>t.replace(/\s+/g," ")),t.includes("t")&&e.push(t=>t.trim()),t.includes("r")&&e.push(t=>t.replace(/(.)\1+/g,"$1")),t.includes("s")&&e.push(t=>t.replace(/[^\p{L}\p{N}\s]/gu,"")),t.includes("k")&&e.push(t=>t.replace(/[^\p{L}]/gu,"")),t.includes("n")&&e.push(t=>t.replace(/\p{N}/gu,"")),t.includes("i")&&e.push(t=>t.toLowerCase());const r=t=>{let r=t;for(const t of e)r=t(r);return r};return u.pipeline.set(t,r),r}static normalize(t,e){if(Array.isArray(t))return t.map(t=>u.normalize(t,e));if(!e||"string"!=typeof e||!t)return t;const r=u.cache.key(e,[t]);if(r&&u.cache.has(r))return u.cache.get(r);const s=u.getPipeline(e)(t);return r&&u.cache.set(r,s),s}static async normalizeAsync(t,e){return await(Array.isArray(t)?Promise.all(t.map(t=>u.normalize(t,e))):Promise.resolve(u.normalize(t,e)))}static clear(){u.pipeline.clear(),u.cache.clear()}}class p{static filters=new Map;static find(t,e){return p.filters.get(t)?.find(t=>t.id===e)}static add(t,e,r,s={}){const{priority:n=10,active:i=!0,overrideable:a=!0}=s,o=p.filters.get(t)??[],c=o.findIndex(t=>t.id===e);if(c>=0){if(!o[c].overrideable)return!1;o.splice(c,1)}return o.push({id:e,fn:r,priority:n,active:i,overrideable:a}),o.sort((t,e)=>t.priority-e.priority),p.filters.set(t,o),!0}static remove(t,e){const r=p.filters.get(t);if(!r)return!1;const s=r.findIndex(t=>t.id===e);return s>=0&&(r.splice(s,1),!0)}static pause(t,e){const r=p.find(t,e);return!!r&&(r.active=!1,!0)}static resume(t,e){const r=p.find(t,e);return!!r&&(r.active=!0,!0)}static list(t,e=!1){const r=p.filters.get(t)??[],s=[];for(const t of r)e&&!t.active||s.push(t.id);return s}static apply(t,e){const r=p.filters.get(t);if(!r||r.every(t=>!t.active))return e;const s=t=>{for(const e of r)e.active&&(t=e.fn(t));return t};return Array.isArray(e)?e.map(s):s(e)}static async applyAsync(t,e){const r=p.filters.get(t);if(!r||r.every(t=>!t.active))return e;const s=async t=>{for(const e of r)e.active&&(t=await Promise.resolve(e.fn(t)));return t};return Array.isArray(e)?Promise.all(e.map(s)):s(e)}static clear(t){t?p.filters.delete(t):p.filters.clear()}}class d{maxSize;buffers=[];pointer=0;constructor(t){this.maxSize=t}acquire(t,e){const r=this.buffers.length;for(let s=0;s<r;s++){const n=(this.pointer+s)%r,i=this.buffers[n];if(i.size>=t)return this.pointer=(n+1)%r,e||i.size===t?i:null}return null}release(t){this.buffers.length<this.maxSize?this.buffers.push(t):(this.buffers[this.pointer]=t,this.pointer=(this.pointer+1)%this.maxSize)}clear(){this.buffers=[],this.pointer=0}}class g{static CONFIG={uint16:{type:"uint16",maxSize:64,maxItemSize:2048,allowOversize:!0},"number[]":{type:"number[]",maxSize:16,maxItemSize:1024,allowOversize:!1},"string[]":{type:"string[]",maxSize:2,maxItemSize:1024,allowOversize:!1},set:{type:"set",maxSize:8,maxItemSize:0,allowOversize:!1},map:{type:"map",maxSize:8,maxItemSize:0,allowOversize:!1}};static POOLS={uint16:new d(64),"number[]":new d(16),"string[]":new d(2),set:new d(8),map:new d(8)};static allocate(t,e){switch(t){case"uint16":return new Uint16Array(e);case"number[]":return new Float64Array(e);case"string[]":return new Array(e);case"set":return new Set;case"map":return new Map}}static acquire(t,e){const r=this.CONFIG[t];if(e>r.maxItemSize)return this.allocate(t,e);const s=this.POOLS[t].acquire(e,r.allowOversize);return s?"uint16"===t?s.buffer.subarray(0,e):s.buffer:this.allocate(t,e)}static acquireMany(t,e){return e.map(e=>this.acquire(t,e))}static release(t,e,r){r<=this.CONFIG[t].maxItemSize&&this.POOLS[t].release({buffer:e,size:r})}}class m{static create(t,e){return new m(t,e)}data;key;constructor(t,e){this.data=t,this.key=e}extractFrom(t,e){const r=g.acquire("string[]",t.length);for(let s=0;s<t.length;s++){const n=t[s][e];r[s]="string"==typeof n?n:String(n??"")}return r}extract(){return this.extractFrom(this.data,this.key)}isMetricResult(t){return"object"==typeof t&&null!==t&&"a"in t&&"b"in t&&"res"in t}isCmpStrResult(t){return"object"==typeof t&&null!==t&&"source"in t&&"target"in t&&"match"in t}normalizeResults(t){if(!Array.isArray(t)||0===t.length)return[];const e=t[0];let r=[];return this.isMetricResult(e)?r=t:this.isCmpStrResult(e)&&(r=t.map(t=>({metric:"unknown",a:t.source,b:t.target,res:t.match,raw:t.raw}))),r.map((t,e)=>({...t,__idx:e}))}rebuild(t,e,r,s,n){const i=new Map;for(let t=0;t<r.length;t++){const e=r[t];i.has(e)||i.set(e,[]),i.get(e).push(t)}const a=new Array(t.length),o=new Map;let c=0;for(let l=0;l<t.length;l++){const h=t[l];if(s&&0===h.res)continue;const u=h.b||"",p=i.get(u);let d;if(p&&p.length>0){const t=o.get(u)??0;o.set(u,t+1),d=p[t%p.length]}else d=h.__idx??l;if(d<0||d>=e.length)continue;const g=e[d],m=r[d]||u;a[c++]=n?g:{obj:g,key:this.key,result:{source:h.a,target:m,match:h.res},...h.raw?{raw:h.raw}:null}}return a.length=c,a}sort(t,e){if(!e||t.length<=1)return t;const r="asc"===e;return t.sort((t,e)=>r?t.res-e.res:e.res-t.res)}performLookup(t,e,r){return this.rebuild(this.sort(this.normalizeResults(t()),r?.sort),this.data,e,r?.removeZero,r?.objectsOnly)}async performLookupAsync(t,e,r){return this.rebuild(this.sort(this.normalizeResults(await t()),r?.sort),this.data,e,r?.removeZero,r?.objectsOnly)}lookup(t,e,r){const s=this.extract();try{return this.performLookup(()=>t(e,s,r),s,r)}finally{g.release("string[]",s,s.length)}}lookupPairs(t,e,r,s){const n=this.extract(),i=this.extractFrom(e,r);try{return this.performLookup(()=>t(n,i,s),n,s)}finally{g.release("string[]",n,n.length),g.release("string[]",i,i.length)}}async lookupAsync(t,e,r){const s=this.extract();try{return await this.performLookupAsync(()=>t(e,s,r),s,r)}finally{g.release("string[]",s,s.length)}}async lookupPairsAsync(t,e,r,s){const n=this.extract(),i=this.extractFrom(e,r);try{return await this.performLookupAsync(()=>t(n,i,s),n,s)}finally{g.release("string[]",n,n.length),g.release("string[]",i,i.length)}}}const f=Object.create(null),y=Object.create(null);function w(t,e){if(t in f||t in y)throw new Error(`Registry <${t}> already exists / overwriting is forbidden`);const r=Object.create(null),s={add(s,n,i=!1){if(!(n.prototype instanceof e))throw new TypeError(`Class must extend <${t}>`);if(!i&&s in r)throw new Error(`Entry <${s}> already exists / use <update=true> to overwrite`);r[s]=n},remove(t){delete r[t]},has:t=>t in r,list:()=>Object.keys(r),get(e){if(!(e in r))throw new Error(`Class <${e}> not registered for <${t}>`);return r[e]}};return f[t]=s,y[t]=(e,...r)=>function(t,e,...r){e=function(t,e){if(!(t in f))throw new ReferenceError(`Registry <${t}> does not exist`);return"string"==typeof e?f[t]?.get(e):e}(t,e);try{return new e(...r)}catch(t){throw new Error(`Cannot instantiate class <${e}>`,{cause:t})}}(t,e,...r),s}const b=a.getInstance();class A{static cache=new h;metric;a;b;origA=[];origB=[];options;symmetric;results;static clear(){this.cache.clear()}static swap(t,e,r,s){return r>s?[e,t,s,r]:[t,e,r,s]}static clamp(t){return Math.max(0,Math.min(1,t))}constructor(t,e,r,s={},n=!1){if(this.metric=t,this.a=Array.isArray(e)?e:[e],this.b=Array.isArray(r)?r:[r],0===this.a.length||0===this.b.length)throw new Error("Inputs <a> and <b> must not be empty");this.options=s,this.symmetric=n}preCompute(t,e,r,s){return t===e?{res:1}:0==r||0==s||r<2&&s<2?{res:0}:void 0}compute(t,e,r,s,n){throw new Error("Method compute() must be overridden in a subclass")}runSingle(t,e){let r=String(this.a[t]),s=r,n=String(this.b[e]),i=n,a=s.length,o=i.length,c=this.preCompute(s,i,a,o);return c||(c=b.run(()=>{const t=A.cache.key(this.metric,[s,i],this.symmetric);return A.cache.get(t||"")??(()=>{this.symmetric&&([s,i,a,o]=A.swap(s,i,a,o));const e=this.compute(s,i,a,o,Math.max(a,o));return t&&A.cache.set(t,e),e})()})),{metric:this.metric,a:this.origA[t]??r,b:this.origB[e]??n,...c}}async runSingleAsync(t,e){return Promise.resolve(this.runSingle(t,e))}runBatch(){const t=[];for(let e=0;e<this.a.length;e++)for(let r=0;r<this.b.length;r++)t.push(this.runSingle(e,r));this.results=t}async runBatchAsync(){const t=[];for(let e=0;e<this.a.length;e++)for(let r=0;r<this.b.length;r++)t.push(await this.runSingleAsync(e,r));this.results=t}runPairwise(){const t=[];for(let e=0;e<this.a.length;e++)t.push(this.runSingle(e,e));this.results=t}async runPairwiseAsync(){const t=[];for(let e=0;e<this.a.length;e++)t.push(await this.runSingleAsync(e,e));this.results=t}setOriginal(t,e){return t&&(this.origA=Array.isArray(t)?t:[t]),e&&(this.origB=Array.isArray(e)?e:[e]),this}isBatch(){return this.a.length>1||this.b.length>1}isSingle(){return!this.isBatch()}isPairwise(t=!1){return!(!this.isBatch()||this.a.length!==this.b.length)||!t&&(()=>{throw new Error("Mode <pairwise> requires arrays of equal length")})()}isSymmetrical(){return this.symmetric}whichMode(t){return t??this.options?.mode??"default"}clear(){this.results=void 0}run(t,e=!0){switch(e&&this.clear(),this.whichMode(t)){case"default":if(this.isSingle()){this.results=this.runSingle(0,0);break}case"batch":this.runBatch();break;case"single":this.results=this.runSingle(0,0);break;case"pairwise":this.isPairwise()&&this.runPairwise();break;default:throw new Error(`Unsupported mode <${t}>`)}}async runAsync(t,e=!0){switch(e&&this.clear(),this.whichMode(t)){case"default":if(this.isSingle()){this.results=await this.runSingleAsync(0,0);break}case"batch":await this.runBatchAsync();break;case"single":this.results=await this.runSingleAsync(0,0);break;case"pairwise":this.isPairwise()&&await this.runPairwiseAsync();break;default:throw new Error(`Unsupported async mode <${t}>`)}}getMetricName(){return this.metric}getResults(){if(void 0===this.results)throw new Error("run() must be called before getResult()");return this.results}}const x=w("metric",A);x.add("cosine",class extends A{constructor(t,e,r={}){super("cosine",t,e,r,!0)}_termFreq(t,e){const r=t.split(e),s=g.acquire("map",r.length);for(const t of r)s.set(t,(s.get(t)||0)+1);return s}compute(t,e){const{delimiter:r=" "}=this.options,s=this._termFreq(t,r),n=this._termFreq(e,r);let i=0,a=0,o=0;for(const[t,e]of s)i+=e*(n.get(t)||0),a+=e*e;for(const t of n.values())o+=t*t;return a=Math.sqrt(a),o=Math.sqrt(o),g.release("map",s,s.size),g.release("map",n,n.size),{res:a&&o?A.clamp(i/(a*o)):0,raw:{dotProduct:i,magnitudeA:a,magnitudeB:o}}}}),x.add("damerau",class extends A{constructor(t,e,r={}){super("damerau",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o,c]=g.acquireMany("uint16",[i,i,i]);for(let t=0;t<=r;t++)o[t]=t;for(let n=1;n<=s;n++){c[0]=n;const s=e.charCodeAt(n-1);for(let i=1;i<=r;i++){const r=t.charCodeAt(i-1),l=r===s?0:1;let h=Math.min(c[i-1]+1,o[i]+1,o[i-1]+l);i>1&&n>1&&r===e.charCodeAt(n-2)&&s===t.charCodeAt(i-2)&&(h=Math.min(h,a[i-2]+l)),c[i]=h}a.set(o),o.set(c)}const l=o[r];return g.release("uint16",a,i),g.release("uint16",o,i),g.release("uint16",c,i),{res:0===n?1:A.clamp(1-l/n),raw:{dist:l,maxLen:n}}}}),x.add("dice",class extends A{constructor(t,e,r={}){super("dice",t,e,r,!0)}_bigrams(t){const e=t.length-1,r=g.acquire("set",e);for(let s=0;s<e;s++)r.add(t.substring(s,s+2));return r}compute(t,e){const r=this._bigrams(t),s=this._bigrams(e);let n=0;for(const t of r)s.has(t)&&n++;const i=r.size,a=s.size,o=i+a;return g.release("set",r,i),g.release("set",s,a),{res:0===o?1:A.clamp(2*n/o),raw:{intersection:n,size:o}}}}),x.add("hamming",class extends A{constructor(t,e,r={}){super("hamming",t,e,r,!0)}compute(t,e,r,s,n){if(r!==s){if(void 0===this.options.pad)throw new Error(`Strings must be of equal length for Hamming Distance, a=${r} and b=${s} given, use option.pad for automatic adjustment`);r<n&&(t=t.padEnd(n,this.options.pad)),s<n&&(e=e.padEnd(n,this.options.pad)),r=s=n}let i=0;for(let r=0;r<t.length;r++)t[r]!==e[r]&&i++;return{res:0===r?1:A.clamp(1-i/r),raw:{dist:i}}}}),x.add("jaccard",class extends A{constructor(t,e,r={}){super("jaccard",t,e,r,!0)}compute(t,e,r,s){const[n,i]=g.acquireMany("set",[r,s]);for(const e of t)n.add(e);for(const t of e)i.add(t);let a=0;for(const t of n)i.has(t)&&a++;const o=n.size+i.size-a;return g.release("set",n,r),g.release("set",i,s),{res:0===o?1:A.clamp(a/o),raw:{intersection:a,union:o}}}}),x.add("jaroWinkler",class extends A{constructor(t,e,r={}){super("jaro-winkler",t,e,r,!0)}compute(t,e,r,s){const n=Math.max(0,Math.floor(s/2)-1),i=g.acquire("uint16",r),a=g.acquire("uint16",s);for(let t=0;t<r;t++)i[t]=0;for(let t=0;t<s;t++)a[t]=0;let o=0;for(let c=0;c<r;c++){const r=Math.max(0,c-n),l=Math.min(c+n+1,s);for(let s=r;s<l;s++)if(!a[s]&&t[c]===e[s]){i[c]=1,a[s]=1,o++;break}}let c=0,l=0,h=0,u=0;if(o>0){let n=0;for(let s=0;s<r;s++)if(i[s]){for(;!a[n];)n++;t[s]!==e[n]&&c++,n++}c/=2,l=(o/r+o/s+(o-c)/o)/3;for(let n=0;n<Math.min(4,r,s)&&t[n]===e[n];n++)h++;u=l+.1*h*(1-l)}return g.release("uint16",i,r),g.release("uint16",a,s),{res:A.clamp(u),raw:{matchWindow:n,matches:o,transpos:c,jaro:l,prefix:h}}}}),x.add("lcs",class extends A{constructor(t,e,r={}){super("lcs",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o]=g.acquireMany("uint16",[i,i]);for(let t=0;t<=r;t++)a[t]=0;for(let n=1;n<=s;n++){o[0]=0;const s=e.charCodeAt(n-1);for(let e=1;e<=r;e++)t.charCodeAt(e-1)===s?o[e]=a[e-1]+1:o[e]=Math.max(a[e],o[e-1]);a.set(o)}const c=a[r];return g.release("uint16",a,i),g.release("uint16",o,i),{res:0===n?1:A.clamp(c/n),raw:{lcs:c,maxLen:n}}}}),x.add("levenshtein",class extends A{constructor(t,e,r={}){super("levenshtein",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o]=g.acquireMany("uint16",[i,i]);for(let t=0;t<=r;t++)a[t]=t;for(let n=1;n<=s;n++){o[0]=n;const s=e.charCodeAt(n-1);for(let e=1;e<=r;e++){const r=t.charCodeAt(e-1)===s?0:1;o[e]=Math.min(o[e-1]+1,a[e]+1,a[e-1]+r)}a.set(o)}const c=a[r];return g.release("uint16",a,i),g.release("uint16",o,i),{res:0===n?1:A.clamp(1-c/n),raw:{dist:c,maxLen:n}}}}),x.add("needlemanWunsch",class extends A{constructor(t,e,r={}){super("needlemanWunsch",t,e,r,!0)}compute(t,e,r,s,n){const{match:i=1,mismatch:a=-1,gap:o=-1}=this.options,c=r+1,[l,h]=g.acquireMany("uint16",[c,c]);l[0]=0;for(let t=1;t<=r;t++)l[t]=l[t-1]+o;for(let n=1;n<=s;n++){h[0]=l[0]+o;const s=e.charCodeAt(n-1);for(let e=1;e<=r;e++){const r=t.charCodeAt(e-1)===s?i:a;h[e]=Math.max(l[e-1]+r,l[e]+o,h[e-1]+o)}l.set(h)}const u=l[r];g.release("uint16",l,c),g.release("uint16",h,c);const p=n*i;return{res:0===p?0:A.clamp(u/p),raw:{score:u,denum:p}}}}),x.add("qGram",class extends A{constructor(t,e,r={}){super("qgram",t,e,r,!0)}_qGrams(t,e){const r=Math.max(0,t.length-e+1),s=g.acquire("set",r);for(let n=0;n<r;n++)s.add(t.slice(n,n+e));return s}compute(t,e){const{q:r=2}=this.options,s=this._qGrams(t,r),n=this._qGrams(e,r);let i=0;for(const t of s)n.has(t)&&i++;const a=s.size,o=n.size,c=Math.max(a,o);return g.release("set",s,a),g.release("set",n,o),{res:0===c?1:A.clamp(i/c),raw:{intersection:i,size:c}}}}),x.add("smithWaterman",class extends A{constructor(t,e,r={}){super("smithWaterman",t,e,r,!0)}compute(t,e,r,s){const{match:n=2,mismatch:i=-1,gap:a=-2}=this.options,o=r+1,[c,l]=g.acquireMany("uint16",[o,o]);for(let t=0;t<=r;t++)c[t]=0;let h=0;for(let o=1;o<=s;o++){l[0]=0;const s=e.charCodeAt(o-1);for(let e=1;e<=r;e++){const r=t.charCodeAt(e-1)===s?n:i;l[e]=Math.max(0,c[e-1]+r,c[e]+a,l[e-1]+a),l[e]>h&&(h=l[e])}c.set(l)}g.release("uint16",c,o),g.release("uint16",l,o);const u=Math.min(r*n,s*n);return{res:0===u?0:A.clamp(h/u),raw:{score:h,denum:u}}}});const v=a.getInstance();class S{static cache=new h;static default;algo;options;map;static clear(){this.cache.clear()}constructor(t,e={}){const r=this.constructor.default??{},n=e.map??r.map;if(!n)throw new Error("No mapping specified for phonetic algorithm");const i=k.get(t,n);if(void 0===i)throw new Error(`Requested mapping <${n}> is not declared`);this.options=s(s(r,i.options??{}),e),this.algo=t,this.map=i}applyPattern(t){const{patterns:e=[]}=this.map;if(!e||!e.length)return t;for(const{pattern:r,replace:s,all:n=!1}of e)t=t[n?"replaceAll":"replace"](r,s);return t}applyRules(t,e,r,s){const{ruleset:n=[]}=this.map;if(!n||!n.length)return;const i=r[e-1]||"",a=r[e-2]||"",o=r[e+1]||"",c=r[e+2]||"";for(const l of n)if((!l.char||l.char===t)&&("start"!==l.position||0===e)&&!("middle"===l.position&&e>0&&e<s)&&("end"!==l.position||e===s)&&(!l.prev||l.prev.includes(i))&&(!l.prevNot||!l.prevNot.includes(i))&&(!l.prev2||l.prev2.includes(a))&&(!l.prev2Not||!l.prev2Not.includes(a))&&(!l.next||l.next.includes(o))&&(!l.nextNot||!l.nextNot.includes(o))&&(!l.next2||l.next2.includes(c))&&(!l.next2Not||!l.next2Not.includes(c))&&(!l.leading||l.leading.includes(r.slice(0,l.leading.length).join("")))&&(!l.trailing||l.trailing.includes(r.slice(-l.trailing.length).join("")))&&(!l.match||l.match.every((t,s)=>r[e+s]===t)))return l.code}encode(t){const{map:e={},ignore:r=[]}=this.map;t=this.applyPattern(t);const s=this.word2Chars(t),n=s.length;let i="",a=null;for(let t=0;t<n;t++){const o=s[t];if(r.includes(o))continue;const c=this.mapChar(o,t,s,n,a,e);if(void 0!==c&&(i+=c,a=c,this.exitEarly(i,t)))break}return this.adjustCode(i,s)}mapChar(t,e,r,s,n,i){const{dedupe:a=!0,fallback:o}=this.options,c=this.applyRules(t,e,r,s)??i[t]??o;return a&&c===n?void 0:c}equalLen(t){const{length:e=-1,pad:r="0"}=this.options;return-1===e?t:(t+r.repeat(e)).slice(0,e)}word2Chars(t){return t.toLowerCase().split("")}exitEarly(t,e){const{length:r=-1}=this.options;return r>0&&t.length>=r}adjustCode(t,e){return t}loop(t){const e=[];for(const r of t){const t=S.cache.key(this.algo,[r]),s=S.cache.get(t||"")??(()=>{const e=this.encode(r);return t&&S.cache.set(t,e),e})();s&&s.length&&e.push(this.equalLen(s))}return e}async loopAsync(t){const e=[];for(const r of t){const t=await Promise.resolve(this.encode(r));t&&t.length&&e.push(this.equalLen(t))}return e}getAlgoName(){return this.algo}getIndex(t){const{delimiter:e=" "}=this.options;return v.run(()=>this.loop(t.split(e).filter(Boolean)).filter(Boolean))}async getIndexAsync(t){const{delimiter:e=" "}=this.options;return(await v.runAsync(async()=>await this.loopAsync(t.split(e).filter(Boolean)))).filter(Boolean)}}const z=w("phonetic",S),k=(()=>{const t=Object.create(null),e=e=>t[e]||=Object.create(null);return{add(t,r,s,n=!1){const i=e(t);if(!n&&r in i)throw new Error(`Entry <${r}> already exists / use <update=true> to overwrite`);i[r]=s},remove(t,r){delete e(t)[r]},has:(t,r)=>r in e(t),get:(t,r)=>e(t)[r],list:t=>Object.keys(e(t))}})();z.add("caverphone",class extends S{static default={map:"en2",delimiter:" ",length:-1,pad:"",dedupe:!1};constructor(t={}){super("caverphone",t)}encode(t){return t=t.replace(/[^A-Z]/gi,"").toLowerCase(),super.encode(t)}mapChar(t){return t}adjustCode(t){return t.toUpperCase()}}),k.add("caverphone","en1",{options:{length:6,pad:"1"},map:{},patterns:[{pattern:/^(c|r|t|en)ough/,replace:"$1ou2f"},{pattern:/^gn/,replace:"2n"},{pattern:/mb$/,replace:"m2"},{pattern:/cq/g,replace:"2q"},{pattern:/c(e|i|y)/g,replace:"s$1"},{pattern:/tch/g,replace:"2ch"},{pattern:/[cqx]/g,replace:"k"},{pattern:/v/g,replace:"f"},{pattern:/dg/g,replace:"2g"},{pattern:/ti(a|o)/g,replace:"si$1"},{pattern:/d/g,replace:"t"},{pattern:/ph/g,replace:"fh"},{pattern:/b/g,replace:"p"},{pattern:/sh/g,replace:"s2"},{pattern:/z/g,replace:"s"},{pattern:/^[aeiou]/,replace:"A"},{pattern:/[aeiou]/g,replace:"3"},{pattern:/3gh3/g,replace:"3kh3"},{pattern:/gh/g,replace:"22"},{pattern:/g/g,replace:"k"},{pattern:/s+/g,replace:"S"},{pattern:/t+/g,replace:"T"},{pattern:/p+/g,replace:"P"},{pattern:/k+/g,replace:"K"},{pattern:/f+/g,replace:"F"},{pattern:/m+/g,replace:"M"},{pattern:/n+/g,replace:"N"},{pattern:/j/g,replace:"y"},{pattern:/l3/g,replace:"L3"},{pattern:/r3/g,replace:"R3"},{pattern:/w3/g,replace:"W3"},{pattern:/y3/g,replace:"Y3"},{pattern:/ly/g,replace:"Ly"},{pattern:/ry/g,replace:"Ry"},{pattern:/wy/g,replace:"Wy"},{pattern:/wh3/g,replace:"Wh3"},{pattern:/why/g,replace:"Why"},{pattern:/^h/,replace:"A"},{pattern:/[hlrwy23]/g,replace:""}]}),k.add("caverphone","en2",{options:{length:10,pad:"1"},map:{},patterns:[{pattern:/e$/,replace:""},{pattern:/^(c|r|t|en|tr)ough/,replace:"$1ou2f"},{pattern:/^gn/,replace:"2n"},{pattern:/mb$/,replace:"m2"},{pattern:/cq/g,replace:"2q"},{pattern:/c(e|i|y)/g,replace:"s$1"},{pattern:/tch/g,replace:"2ch"},{pattern:/[cqx]/g,replace:"k"},{pattern:/v/g,replace:"f"},{pattern:/dg/g,replace:"2g"},{pattern:/ti(a|o)/g,replace:"si$1"},{pattern:/d/g,replace:"t"},{pattern:/ph/g,replace:"fh"},{pattern:/b/g,replace:"p"},{pattern:/sh/g,replace:"s2"},{pattern:/z/g,replace:"s"},{pattern:/^[aeiou]/,replace:"A"},{pattern:/[aeiou]/g,replace:"3"},{pattern:/j/g,replace:"y"},{pattern:/^y3/,replace:"Y3"},{pattern:/^y/,replace:"A"},{pattern:/y/g,replace:"3"},{pattern:/3gh3/g,replace:"3kh3"},{pattern:/gh/g,replace:"22"},{pattern:/g/g,replace:"k"},{pattern:/s+/g,replace:"S"},{pattern:/t+/g,replace:"T"},{pattern:/p+/g,replace:"P"},{pattern:/k+/g,replace:"K"},{pattern:/f+/g,replace:"F"},{pattern:/m+/g,replace:"M"},{pattern:/n+/g,replace:"N"},{pattern:/l3/g,replace:"L3"},{pattern:/r3/g,replace:"R3"},{pattern:/w3/g,replace:"W3"},{pattern:/wh3/g,replace:"Wh3"},{pattern:/[lrw]$/,replace:"3"},{pattern:/^h/,replace:"A"},{pattern:/3$/,replace:"A"},{pattern:/[hlrw23]/g,replace:""}]}),z.add("cologne",class extends S{static default={map:"default",delimiter:" ",length:-1,dedupe:!0};constructor(t={}){super("cologne",t)}adjustCode(t){return t.slice(0,1)+t.slice(1).replaceAll("0","")}}),k.add("cologne","default",{map:{a:"0","ä":"0",e:"0",i:"0",j:"0",o:"0","ö":"0",u:"0","ü":"0",y:"0",b:"1",p:"1",d:"2",t:"2",f:"3",v:"3",w:"3",g:"4",k:"4",q:"4",l:"5",m:"6",n:"6",r:"7",c:"8",s:"8","ß":"8",z:"8",x:"48"},ignore:["h"],ruleset:[{char:"p",next:["h"],code:"3"},{char:"c",position:"start",next:["a","h","k","l","o","q","r","u","x"],code:"4"},{char:"c",next:["a","h","k","o","q","u","x"],prevNot:["s","z"],code:"4"},{char:"d",next:["c","s","z"],code:"8"},{char:"t",next:["c","s","z"],code:"8"},{char:"x",prev:["c","k","q"],code:"8"}]}),z.add("metaphone",class extends S{static default={map:"en90",delimiter:" ",length:-1,pad:"",dedupe:!1};constructor(t={}){super("metaphone",t)}encode(t){return t=t.replace(/([A-BD-Z])\1+/gi,(t,e)=>"C"===e?t:e),super.encode(t)}adjustCode(t){return t.slice(0,1)+t.slice(1).replace(/[AEIOU]/g,"")}}),k.add("metaphone","en90",{map:{a:"A",b:"B",c:"K",d:"T",e:"E",f:"F",g:"K",h:"H",i:"I",j:"J",k:"K",l:"L",m:"M",n:"N",o:"O",p:"P",q:"K",r:"R",s:"S",t:"T",u:"U",v:"F",w:"W",x:"KS",y:"Y",z:"S"},ruleset:[{char:"a",position:"start",next:["e"],code:""},{char:"g",position:"start",next:["n"],code:""},{char:"k",position:"start",next:["n"],code:""},{char:"p",position:"start",next:["n"],code:""},{char:"w",position:"start",next:["r"],code:""},{char:"b",position:"end",prev:["m"],code:""},{char:"c",next:["h"],prevNot:["s"],code:"X"},{char:"c",next:["i"],next2:["a"],code:"X"},{char:"c",next:["e","i","y"],code:"S"},{char:"d",next:["g"],next2:["e","i","y"],code:"J"},{char:"g",next:["h"],next2Not:["","a","e","i","o","u"],code:""},{char:"g",trailing:"n",code:""},{char:"g",trailing:"ned",code:""},{char:"g",next:["e","i","y"],prevNot:["g"],code:"J"},{char:"h",prev:["a","e","i","o","u"],nextNot:["a","e","i","o","u"],code:""},{char:"h",prev:["c","g","p","s","t"],code:""},{char:"k",prev:["c"],code:""},{char:"p",next:["h"],code:"F"},{char:"s",next:["h"],code:"X"},{char:"s",next:["i"],next2:["a","o"],code:"X"},{char:"t",next:["i"],next2:["a","o"],code:"X"},{char:"t",next:["h"],code:"0"},{char:"t",next:["c"],next2:["h"],code:""},{char:"w",nextNot:["a","e","i","o","u"],code:""},{char:"h",leading:"w",code:""},{char:"x",position:"start",code:"S"},{char:"y",nextNot:["a","e","i","o","u"],code:""}]}),z.add("soundex",class extends S{static default={map:"en",delimiter:" ",length:4,pad:"0",dedupe:!0};constructor(t={}){super("soundex",t)}adjustCode(t,e){return e[0].toUpperCase()+t.slice(1).replaceAll("0","")}}),k.add("soundex","en",{map:{a:"0",e:"0",h:"0",i:"0",o:"0",u:"0",w:"0",y:"0",b:"1",f:"1",p:"1",v:"1",c:"2",g:"2",j:"2",k:"2",q:"2",s:"2",x:"2",z:"2",d:"3",t:"3",l:"4",m:"5",n:"5",r:"6"}}),k.add("soundex","de",{map:{a:"0","ä":"0",e:"0",h:"0",i:"0",j:"0",o:"0","ö":"0",u:"0","ü":"0",y:"0",b:"1",f:"1",p:"1",v:"1",w:"1",c:"2",g:"2",k:"2",q:"2",s:"2","ß":"2",x:"2",z:"2",d:"3",t:"3",l:"4",m:"5",n:"5",r:"6"},ruleset:[{char:"c",next:["h"],code:"7"}]});const M=a.getInstance();class C{static filter={add:p.add,remove:p.remove,pause:p.pause,resume:p.resume,list:p.list,clear:p.clear};static metric={add:x.add,remove:x.remove,has:x.has,list:x.list};static phonetic={add:z.add,remove:z.remove,has:z.has,list:z.list,map:{add:k.add,remove:k.remove,has:k.has,list:k.list}};static profiler=M.services;static clearCache={normalizer:u.clear,metric:A.clear,phonetic:S.clear};static analyze(t){return new o(t)}static diff(t,e,r){return new c(t,e,r)}static create(t){return new C(t)}options=Object.create(null);constructor(t){t&&("string"==typeof t?this.setSerializedOptions(t):this.setOptions(t))}assert(t,e){switch(t){case"metric":if(!C.metric.has(e))throw new Error("CmpStr <metric> must be set, call .setMetric(), use CmpStr.metric.list() for available metrics");break;case"phonetic":if(!C.phonetic.has(e))throw new Error("CmpStr <phonetic> must be set, call .setPhonetic(), use CmpStr.phonetic.list() for available phonetic algorithms");break;default:throw new Error(`Cmpstr condition <${t}> unknown`)}}assertMany(...t){for(const[e,r]of t)this.assert(e,r)}resolveOptions(t){return s({...this.options??Object.create(null)},t)}normalize(t,e){return u.normalize(t,e??this.options.flags??"")}filter(t,e){return p.apply(e,t)}prepare(t,e){const{flags:r,processors:s}=e??this.options;return r?.length&&(t=this.normalize(t,r)),t=this.filter(t,"input"),s?.phonetic&&(t=this.index(t,s.phonetic)),t}postProcess(t,e){return e?.removeZero&&Array.isArray(t)&&(t=t.filter(t=>t.res>0)),t}index(t,{algo:e,opt:r}){this.assert("phonetic",e);const s=y.phonetic(e,r),n=r?.delimiter??" ";return Array.isArray(t)?t.map(t=>s.getIndex(t).join(n)):s.getIndex(t).join(n)}structured(t,e){return m.create(t,e)}compute(t,e,r,s,n,i){const a=this.resolveOptions(r);this.assert("metric",a.metric);const o=i?t:this.prepare(t,a),c=i?e:this.prepare(e,a);if(a.safeEmpty&&(Array.isArray(o)&&0===o.length||Array.isArray(c)&&0===c.length||""===o||""===c))return[];const l=y.metric(a.metric,o,c,a.opt);"prep"!==a.output&&l.setOriginal(t,e),l.run(s);const h=this.postProcess(l.getResults(),a);return this.output(h,n??a.raw)}output(t,e){return e??this.options.raw?t:Array.isArray(t)?t.map(t=>({source:t.a,target:t.b,match:t.res})):{source:t.a,target:t.b,match:t.res}}clone(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)}reset(){for(const t in this.options)delete this.options[t];return this}setOptions(t){return this.options=t,this}mergeOptions(t){return s(this.options,t),this}setSerializedOptions(t){return this.options=JSON.parse(t),this}setOption(t,e){return r(this.options,t,e),this}rmvOption(t){return n(this.options,t),this}setRaw(t){return this.setOption("raw",t)}setMetric(t){return this.setOption("metric",t)}setFlags(t){return this.setOption("flags",t)}rmvFlags(){return this.rmvOption("flags")}setProcessors(t){return this.setOption("processors",t)}rmvProcessors(){return this.rmvOption("processors")}getOptions(){return this.options}getSerializedOptions(){return JSON.stringify(this.options)}getOption(t){return e(this.options,t)}test(t,e,r){return this.compute(t,e,r,"single")}compare(t,e,r){return this.compute(t,e,r,"single",!0).res}batchTest(t,e,r){return this.compute(t,e,r,"batch")}batchSorted(t,e,r="desc",s){return this.output(this.compute(t,e,s,"batch",!0).sort((t,e)=>"asc"===r?t.res-e.res:e.res-t.res),s?.raw??this.options.raw)}pairs(t,e,r){return this.compute(t,e,r,"pairwise")}match(t,e,r,s){return this.output(this.compute(t,e,s,"batch",!0).filter(t=>t.res>=r).sort((t,e)=>e.res-t.res),s?.raw??this.options.raw)}closest(t,e,r=1,s){return this.batchSorted(t,e,"desc",s).slice(0,r)}furthest(t,e,r=1,s){return this.batchSorted(t,e,"asc",s).slice(0,r)}search(t,e,r,s){const n=this.resolveOptions({flags:r,processors:s}),i=this.prepare(t,n),a=this.prepare(e,n);return e.filter((t,e)=>a[e].includes(i))}matrix(t,e){return(t=this.prepare(t,this.resolveOptions(e))).map(e=>this.compute(e,t,void 0,"batch",!0,!0).map(t=>t.res??0))}phoneticIndex(t,e,r){const{algo:s,opt:n}=this.options.processors?.phonetic??{};return this.index(t,{algo:e??s,opt:r??n})}structuredLookup(t,e,r,s){return this.structured(e,r).lookup((t,e,r)=>this.batchTest(t,e,r),t,s)}structuredMatch(t,e,r,s,n){return this.structured(e,r).lookup((t,e,r)=>this.match(t,e,s,r),t,{...n,sort:"desc"})}structuredClosest(t,e,r,s=1,n){return this.structured(e,r).lookup((t,e,r)=>this.closest(t,e,s,r),t,{...n,sort:"desc"})}structuredFurthest(t,e,r,s=1,n){return this.structured(e,r).lookup((t,e,r)=>this.furthest(t,e,s,r),t,{...n,sort:"asc"})}structuredPairs(t,e,r,s,n){return this.structured(t,e).lookupPairs((t,e,r)=>this.pairs(t,e,r),r,s,n)}}class O extends C{static create(t){return new O(t)}constructor(t){super(t)}async normalizeAsync(t,e){return u.normalizeAsync(t,e??this.options.flags??"")}async filterAsync(t,e){return p.applyAsync(e,t)}async prepareAsync(t,e){const{flags:r,processors:s}=e??this.options;return r?.length&&(t=await this.normalizeAsync(t,r)),t=await this.filterAsync(t,"input"),s?.phonetic&&(t=await this.indexAsync(t,s.phonetic)),t}async indexAsync(t,{algo:e,opt:r}){this.assert("phonetic",e);const s=y.phonetic(e,r),n=r?.delimiter??" ";return Array.isArray(t)?Promise.all(t.map(t=>s.getIndexAsync(t).then(t=>t.join(n)))):s.getIndexAsync(t).then(t=>t.join(n))}async computeAsync(t,e,r,s,n,i){const a=this.resolveOptions(r);this.assert("metric",a.metric);const o=i?t:await this.prepareAsync(t,a),c=i?e:await this.prepareAsync(e,a);if(a.safeEmpty&&(Array.isArray(o)&&0===o.length||Array.isArray(c)&&0===c.length||""===o||""===c))return[];const l=y.metric(a.metric,o,c,a.opt);"prep"!==a.output&&l.setOriginal(t,e),await l.runAsync(s);const h=this.postProcess(l.getResults(),a);return this.output(h,n??a.raw)}async testAsync(t,e,r){return this.computeAsync(t,e,r,"single")}async compareAsync(t,e,r){return(await this.computeAsync(t,e,r,"single",!0)).res}async batchTestAsync(t,e,r){return this.computeAsync(t,e,r,"batch")}async batchSortedAsync(t,e,r="desc",s){const n=await this.computeAsync(t,e,s,"batch",!0);return this.output(n.sort((t,e)=>"asc"===r?t.res-e.res:e.res-t.res),s?.raw??this.options.raw)}async pairsAsync(t,e,r){return this.computeAsync(t,e,r,"pairwise")}async matchAsync(t,e,r,s){const n=await this.computeAsync(t,e,s,"batch",!0);return this.output(n.filter(t=>t.res>=r).sort((t,e)=>e.res-t.res),s?.raw??this.options.raw)}async closestAsync(t,e,r=1,s){return(await this.batchSortedAsync(t,e,"desc",s)).slice(0,r)}async furthestAsync(t,e,r=1,s){return(await this.batchSortedAsync(t,e,"asc",s)).slice(0,r)}async searchAsync(t,e,r,s){const n=this.resolveOptions({flags:r,processors:s}),i=await this.prepareAsync(t,n),a=await this.prepareAsync(e,n);return e.filter((t,e)=>a[e].includes(i))}async matrixAsync(t,e){return t=await this.prepareAsync(t,this.resolveOptions(e)),Promise.all(t.map(async e=>await this.computeAsync(e,t,void 0,"batch",!0,!0).then(t=>t.map(t=>t.res??0))))}async phoneticIndexAsync(t,e,r){const{algo:s,opt:n}=this.options.processors?.phonetic??{};return this.indexAsync(t,{algo:e??s,opt:r??n})}async structuredLookupAsync(t,e,r,s){return await this.structured(e,r).lookupAsync((t,e,r)=>this.batchTestAsync(t,e,r),t,s)}async structuredMatchAsync(t,e,r,s,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.matchAsync(t,e,s,r),t,{...n,sort:"desc"})}async structuredClosestAsync(t,e,r,s=1,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.closestAsync(t,e,s,r),t,{...n,sort:"desc"})}async structuredFurthestAsync(t,e,r,s=1,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.furthestAsync(t,e,s,r),t,{...n,sort:"asc"})}async structuredPairsAsync(t,e,r,s,n){return await this.structured(t,e).lookupPairsAsync((t,e,r)=>this.pairsAsync(t,e,r),r,s,n)}}export{C as CmpStr,O as CmpStrAsync,i as DeepMerge,c as DiffChecker,p as Filter,h as HashTable,A as Metric,x as MetricRegistry,u as Normalizer,S as Phonetic,k as PhoneticMappingRegistry,z as PhoneticRegistry,g as Pool,a as Profiler,m as StructuredData,o as TextAnalyzer};
8
8
  //# sourceMappingURL=CmpStr.esm.min.js.map