cmpstr 3.2.0 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +26 -18
  2. package/dist/CmpStr.esm.js +490 -220
  3. package/dist/CmpStr.esm.min.js +2 -3
  4. package/dist/CmpStr.umd.js +489 -220
  5. package/dist/CmpStr.umd.min.js +2 -3
  6. package/dist/cjs/CmpStr.cjs +58 -36
  7. package/dist/cjs/CmpStrAsync.cjs +30 -24
  8. package/dist/cjs/index.cjs +1 -2
  9. package/dist/cjs/metric/Cosine.cjs +1 -2
  10. package/dist/cjs/metric/DamerauLevenshtein.cjs +1 -2
  11. package/dist/cjs/metric/DiceSorensen.cjs +1 -2
  12. package/dist/cjs/metric/Hamming.cjs +5 -4
  13. package/dist/cjs/metric/Jaccard.cjs +1 -2
  14. package/dist/cjs/metric/JaroWinkler.cjs +1 -2
  15. package/dist/cjs/metric/LCS.cjs +1 -2
  16. package/dist/cjs/metric/Levenshtein.cjs +1 -2
  17. package/dist/cjs/metric/Metric.cjs +57 -38
  18. package/dist/cjs/metric/NeedlemanWunsch.cjs +1 -2
  19. package/dist/cjs/metric/QGram.cjs +1 -2
  20. package/dist/cjs/metric/SmithWaterman.cjs +1 -2
  21. package/dist/cjs/phonetic/Caverphone.cjs +1 -2
  22. package/dist/cjs/phonetic/Cologne.cjs +1 -2
  23. package/dist/cjs/phonetic/Metaphone.cjs +1 -2
  24. package/dist/cjs/phonetic/Phonetic.cjs +55 -35
  25. package/dist/cjs/phonetic/Soundex.cjs +1 -2
  26. package/dist/cjs/root.cjs +3 -2
  27. package/dist/cjs/utils/DeepMerge.cjs +10 -5
  28. package/dist/cjs/utils/DiffChecker.cjs +1 -2
  29. package/dist/cjs/utils/Errors.cjs +103 -0
  30. package/dist/cjs/utils/Filter.cjs +56 -27
  31. package/dist/cjs/utils/HashTable.cjs +1 -2
  32. package/dist/cjs/utils/Normalizer.cjs +54 -34
  33. package/dist/cjs/utils/Pool.cjs +42 -18
  34. package/dist/cjs/utils/Profiler.cjs +1 -2
  35. package/dist/cjs/utils/Registry.cjs +46 -22
  36. package/dist/cjs/utils/StructuredData.cjs +13 -5
  37. package/dist/cjs/utils/TextAnalyzer.cjs +1 -2
  38. package/dist/esm/CmpStr.mjs +56 -32
  39. package/dist/esm/CmpStrAsync.mjs +26 -20
  40. package/dist/esm/index.mjs +1 -2
  41. package/dist/esm/metric/Cosine.mjs +1 -2
  42. package/dist/esm/metric/DamerauLevenshtein.mjs +1 -2
  43. package/dist/esm/metric/DiceSorensen.mjs +1 -2
  44. package/dist/esm/metric/Hamming.mjs +5 -4
  45. package/dist/esm/metric/Jaccard.mjs +1 -2
  46. package/dist/esm/metric/JaroWinkler.mjs +1 -2
  47. package/dist/esm/metric/LCS.mjs +1 -2
  48. package/dist/esm/metric/Levenshtein.mjs +1 -2
  49. package/dist/esm/metric/Metric.mjs +59 -38
  50. package/dist/esm/metric/NeedlemanWunsch.mjs +1 -2
  51. package/dist/esm/metric/QGram.mjs +1 -2
  52. package/dist/esm/metric/SmithWaterman.mjs +1 -2
  53. package/dist/esm/phonetic/Caverphone.mjs +1 -2
  54. package/dist/esm/phonetic/Cologne.mjs +1 -2
  55. package/dist/esm/phonetic/Metaphone.mjs +1 -2
  56. package/dist/esm/phonetic/Phonetic.mjs +55 -35
  57. package/dist/esm/phonetic/Soundex.mjs +1 -2
  58. package/dist/esm/root.mjs +3 -2
  59. package/dist/esm/utils/DeepMerge.mjs +10 -5
  60. package/dist/esm/utils/DiffChecker.mjs +1 -2
  61. package/dist/esm/utils/Errors.mjs +103 -0
  62. package/dist/esm/utils/Filter.mjs +56 -27
  63. package/dist/esm/utils/HashTable.mjs +1 -2
  64. package/dist/esm/utils/Normalizer.mjs +54 -34
  65. package/dist/esm/utils/Pool.mjs +38 -18
  66. package/dist/esm/utils/Profiler.mjs +1 -2
  67. package/dist/esm/utils/Registry.mjs +46 -22
  68. package/dist/esm/utils/StructuredData.mjs +13 -5
  69. package/dist/esm/utils/TextAnalyzer.mjs +1 -2
  70. package/dist/types/CmpStr.d.ts +12 -6
  71. package/dist/types/CmpStrAsync.d.ts +6 -4
  72. package/dist/types/index.d.ts +3 -2
  73. package/dist/types/metric/Cosine.d.ts +2 -1
  74. package/dist/types/metric/DamerauLevenshtein.d.ts +2 -1
  75. package/dist/types/metric/DiceSorensen.d.ts +2 -1
  76. package/dist/types/metric/Hamming.d.ts +2 -1
  77. package/dist/types/metric/Jaccard.d.ts +2 -1
  78. package/dist/types/metric/JaroWinkler.d.ts +2 -1
  79. package/dist/types/metric/LCS.d.ts +2 -1
  80. package/dist/types/metric/Levenshtein.d.ts +2 -1
  81. package/dist/types/metric/Metric.d.ts +7 -5
  82. package/dist/types/metric/NeedlemanWunsch.d.ts +2 -1
  83. package/dist/types/metric/QGram.d.ts +2 -1
  84. package/dist/types/metric/SmithWaterman.d.ts +2 -1
  85. package/dist/types/metric/index.d.ts +1 -0
  86. package/dist/types/phonetic/Caverphone.d.ts +2 -1
  87. package/dist/types/phonetic/Cologne.d.ts +2 -1
  88. package/dist/types/phonetic/Metaphone.d.ts +2 -1
  89. package/dist/types/phonetic/Phonetic.d.ts +4 -1
  90. package/dist/types/phonetic/Soundex.d.ts +2 -1
  91. package/dist/types/phonetic/index.d.ts +1 -0
  92. package/dist/types/root.d.ts +2 -1
  93. package/dist/types/utils/DeepMerge.d.ts +3 -2
  94. package/dist/types/utils/DiffChecker.d.ts +2 -1
  95. package/dist/types/utils/Errors.d.ts +137 -0
  96. package/dist/types/utils/Filter.d.ts +33 -22
  97. package/dist/types/utils/HashTable.d.ts +2 -1
  98. package/dist/types/utils/Normalizer.d.ts +5 -1
  99. package/dist/types/utils/Pool.d.ts +4 -1
  100. package/dist/types/utils/Profiler.d.ts +3 -2
  101. package/dist/types/utils/Registry.d.ts +5 -4
  102. package/dist/types/utils/StructuredData.d.ts +5 -2
  103. package/dist/types/utils/TextAnalyzer.d.ts +2 -1
  104. package/dist/types/utils/Types.d.ts +34 -2
  105. package/package.json +10 -7
  106. package/dist/CmpStr.esm.js.map +0 -1
  107. package/dist/CmpStr.esm.min.js.map +0 -1
  108. package/dist/CmpStr.umd.js.map +0 -1
  109. package/dist/CmpStr.umd.min.js.map +0 -1
  110. package/dist/cjs/CmpStr.cjs.map +0 -1
  111. package/dist/cjs/CmpStrAsync.cjs.map +0 -1
  112. package/dist/cjs/index.cjs.map +0 -1
  113. package/dist/cjs/metric/Cosine.cjs.map +0 -1
  114. package/dist/cjs/metric/DamerauLevenshtein.cjs.map +0 -1
  115. package/dist/cjs/metric/DiceSorensen.cjs.map +0 -1
  116. package/dist/cjs/metric/Hamming.cjs.map +0 -1
  117. package/dist/cjs/metric/Jaccard.cjs.map +0 -1
  118. package/dist/cjs/metric/JaroWinkler.cjs.map +0 -1
  119. package/dist/cjs/metric/LCS.cjs.map +0 -1
  120. package/dist/cjs/metric/Levenshtein.cjs.map +0 -1
  121. package/dist/cjs/metric/Metric.cjs.map +0 -1
  122. package/dist/cjs/metric/NeedlemanWunsch.cjs.map +0 -1
  123. package/dist/cjs/metric/QGram.cjs.map +0 -1
  124. package/dist/cjs/metric/SmithWaterman.cjs.map +0 -1
  125. package/dist/cjs/phonetic/Caverphone.cjs.map +0 -1
  126. package/dist/cjs/phonetic/Cologne.cjs.map +0 -1
  127. package/dist/cjs/phonetic/Metaphone.cjs.map +0 -1
  128. package/dist/cjs/phonetic/Phonetic.cjs.map +0 -1
  129. package/dist/cjs/phonetic/Soundex.cjs.map +0 -1
  130. package/dist/cjs/root.cjs.map +0 -1
  131. package/dist/cjs/utils/DeepMerge.cjs.map +0 -1
  132. package/dist/cjs/utils/DiffChecker.cjs.map +0 -1
  133. package/dist/cjs/utils/Filter.cjs.map +0 -1
  134. package/dist/cjs/utils/HashTable.cjs.map +0 -1
  135. package/dist/cjs/utils/Normalizer.cjs.map +0 -1
  136. package/dist/cjs/utils/Pool.cjs.map +0 -1
  137. package/dist/cjs/utils/Profiler.cjs.map +0 -1
  138. package/dist/cjs/utils/Registry.cjs.map +0 -1
  139. package/dist/cjs/utils/StructuredData.cjs.map +0 -1
  140. package/dist/cjs/utils/TextAnalyzer.cjs.map +0 -1
  141. package/dist/esm/CmpStr.mjs.map +0 -1
  142. package/dist/esm/CmpStrAsync.mjs.map +0 -1
  143. package/dist/esm/index.mjs.map +0 -1
  144. package/dist/esm/metric/Cosine.mjs.map +0 -1
  145. package/dist/esm/metric/DamerauLevenshtein.mjs.map +0 -1
  146. package/dist/esm/metric/DiceSorensen.mjs.map +0 -1
  147. package/dist/esm/metric/Hamming.mjs.map +0 -1
  148. package/dist/esm/metric/Jaccard.mjs.map +0 -1
  149. package/dist/esm/metric/JaroWinkler.mjs.map +0 -1
  150. package/dist/esm/metric/LCS.mjs.map +0 -1
  151. package/dist/esm/metric/Levenshtein.mjs.map +0 -1
  152. package/dist/esm/metric/Metric.mjs.map +0 -1
  153. package/dist/esm/metric/NeedlemanWunsch.mjs.map +0 -1
  154. package/dist/esm/metric/QGram.mjs.map +0 -1
  155. package/dist/esm/metric/SmithWaterman.mjs.map +0 -1
  156. package/dist/esm/phonetic/Caverphone.mjs.map +0 -1
  157. package/dist/esm/phonetic/Cologne.mjs.map +0 -1
  158. package/dist/esm/phonetic/Metaphone.mjs.map +0 -1
  159. package/dist/esm/phonetic/Phonetic.mjs.map +0 -1
  160. package/dist/esm/phonetic/Soundex.mjs.map +0 -1
  161. package/dist/esm/root.mjs.map +0 -1
  162. package/dist/esm/utils/DeepMerge.mjs.map +0 -1
  163. package/dist/esm/utils/DiffChecker.mjs.map +0 -1
  164. package/dist/esm/utils/Filter.mjs.map +0 -1
  165. package/dist/esm/utils/HashTable.mjs.map +0 -1
  166. package/dist/esm/utils/Normalizer.mjs.map +0 -1
  167. package/dist/esm/utils/Pool.mjs.map +0 -1
  168. package/dist/esm/utils/Profiler.mjs.map +0 -1
  169. package/dist/esm/utils/Registry.mjs.map +0 -1
  170. package/dist/esm/utils/StructuredData.mjs.map +0 -1
  171. package/dist/esm/utils/TextAnalyzer.mjs.map +0 -1
@@ -1,8 +1,7 @@
1
1
  /**
2
- * CmpStr v3.2.0 build-6929b12-260122
2
+ * CmpStr v3.2.2 build-bb61120-260311
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
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CmpStr={})}(this,function(t){"use strict";const e=/\[(\d+)]/g,r=new Map;function s(t){let s=r.get(t);if(s)return s;const n=t.replace(e,".$1").split(".").map(t=>{const e=Number(t);return Number.isInteger(e)&&String(e)===t?e:t});return r.set(t,n),n}function n(t,e,r){let n=t;for(const t of s(e)){if(null==n||!(t in n))return r;n=n[t]}return n}function i(t,e,r){if(""===e)return r;const n=s(e);if(void 0!==t&&("object"!=typeof t||null===t))throw Error(`Cannot set property <${n[0]}> of <${JSON.stringify(t)}>`);const i=t??("number"==typeof n[0]?[]:Object.create(null));let a=i;for(let t=0;t<n.length-1;t++){const e=n[t];let r=a[e];if(null!=r&&"object"!=typeof r)throw Error(`Cannot set property <${n[t+1]}> of <${JSON.stringify(r)}>`);null==r&&(r=a[e]="number"==typeof n[t+1]?[]:Object.create(null)),a=r}return a[n[n.length-1]]=r,i}function a(t=Object.create(null),e=Object.create(null),r=!1){const s=t??Object.create(null);return Object.keys(e).forEach(t=>{const n=e[t];if((r||void 0!==n)&&"__proto__"!==t&&"constructor"!==t)if(null===n||"object"!=typeof n||Array.isArray(n))s[t]=n;else{const e=s[t];s[t]=a(null===e||"object"!=typeof e||Array.isArray(e)?Object.create(null):e,n,r)}}),s}function o(t,e,r=!1){const n=s(e),i=(t,e=0)=>{const s=n[e];if(!t||"object"!=typeof t)return!1;if(e===n.length-1)return delete t[s];if(!i(t[s],e+1))return!1;if(!r){const e=t[s];"object"==typeof e&&(Array.isArray(e)&&e.every(t=>null==t)||!Array.isArray(e)&&0===Object.keys(e).length)&&delete t[s]}return!0};return i(t),t}var c=Object.freeze({__proto__:null,get:n,has:function(t,e){let r=t;for(const t of s(e)){if(null==r||!(t in r))return!1;r=r[t]}return!0},merge:a,rmv:o,set:i});class l{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){switch(this.options.mode){case"line":return[t];case"word":return t.split(/\s+/)}}concat(t){return t.join("word"===this.options.mode?" ":"")}computeDiff(){if(this.diffRun)return;const{linesA:t,linesB:e,maxLen:r}=this.text2lines();for(let s=0;s<r;s++)this.lineDiff(t[s]||"",e[s]||"",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;switch(s){case"line":a!==o&&(c.push({posA:0,posB:0,del:t,ins:e,size:e.length-t.length}),l=t.length,h=e.length);break;case"word":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,p=n(i),u=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:p[y]??0,posB:u[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:p[y]??0,posB:u[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),p=(e,r)=>t?`[${r}m${e}`:e,u=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} @@`,p(e,"36")} ${i?(t=>p(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")}`,p(r,"31")}`),w.push(`${" ".repeat(h)} ${(t=>p(t,"32"))(`+ ${y(c[t],s.diffs,"ins")}`)}`)):w.push(`${n} ${(t=>p(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?u(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=()=>this.entries;getGroupedDiff=()=>this.grouped;getASCIIDiff=()=>this.output(!1);getCLIDiff=()=>this.output(!0)}class h{static filters=new Map;static pipeline=new Map;static getPipeline(t){const e=h.pipeline.get(t);if(e)return e;const r=h.filters.get(t);if(!r)return t=>t;const s=Array.from(r.values()).filter(t=>t.active).sort((t,e)=>t.priority-e.priority).map(t=>t.fn),n=t=>s.reduce((t,e)=>e(t),t);return h.pipeline.set(t,n),n}static has(t,e){return!!h.filters.get(t)?.has(e)}static add(t,e,r,s={}){const{priority:n=10,active:i=!0,overrideable:a=!0}=s,o=h.filters.get(t)??new Map,c=o.get(e);return!(c&&!c.overrideable||(o.set(e,{id:e,fn:r,priority:n,active:i,overrideable:a}),h.filters.set(t,o),h.pipeline.delete(t),0))}static remove(t,e){h.pipeline.delete(t);const r=h.filters.get(t);return!!r&&r.delete(e)}static pause(t,e){h.pipeline.delete(t);const r=h.filters.get(t)?.get(e);return!(!r||(r.active=!1,0))}static resume(t,e){h.pipeline.delete(t);const r=h.filters.get(t)?.get(e);return!(!r||(r.active=!0,0))}static list(t,e=!1){const r=h.filters.get(t);if(!r)return[];const s=[];for(const t of r.values())e&&!t.active||s.push(t.id);return s}static apply(t,e){const r=h.getPipeline(t);return Array.isArray(e)?e.map(r):r(e)}static async applyAsync(t,e){const r=h.getPipeline(t);return Array.isArray(e)?Promise.all(e.map(r)):Promise.resolve(r(e))}static clear(t){t?h.filters.delete(t):h.filters.clear()}}class p{static FNV_PRIME=16777619;static HASH_OFFSET=2166136261;static fastFNV1a(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=Math.imul(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=Math.imul(r,this.FNV_PRIME)}return r^=r>>>16,r*=2246822507,r^=r>>>13,r*=3266489909,r^=r>>>16,r>>>0}}class u{LRU;static MAX_LEN=2048;static TABLE_SIZE=1e4;table=new Map;constructor(t=!0){this.LRU=t}key(t,e,r=!1){for(const t of e)if(t.length>u.MAX_LEN)return!1;const s=e.map(t=>p.fastFNV1a(t));return[t,...r?s.sort():s].join("-")}has=t=>this.table.has(t);get=t=>this.table.get(t);set(t,e,r=!0){if(!r&&this.table.has(t))return!1;for(;!this.table.has(t)&&this.table.size>=u.TABLE_SIZE;){if(!this.LRU)return!1;this.table.delete(this.table.keys().next().value)}return this.table.set(t,e),!0}delete=t=>this.table.delete(t);clear=()=>this.table.clear();size=()=>this.table.size}class d{static pipeline=new Map;static cache=new u;static REGEX={whitespace:/\s+/g,doubleChars:/(.)\1+/g,specialChars:/[^\p{L}\p{N}\s]/gu,nonLetters:/[^\p{L}]/gu,nonNumbers:/\p{N}/gu};static canonicalFlags(t){return Array.from(new Set(t)).sort().join("")}static getPipeline(t){if(d.pipeline.has(t))return d.pipeline.get(t);const{REGEX:e}=d,r=[["d",t=>t.normalize("NFD")],["i",t=>t.toLowerCase()],["k",t=>t.replace(e.nonLetters,"")],["n",t=>t.replace(e.nonNumbers,"")],["r",t=>t.replace(e.doubleChars,"$1")],["s",t=>t.replace(e.specialChars,"")],["t",t=>t.trim()],["u",t=>t.normalize("NFC")],["w",t=>t.replace(e.whitespace," ")],["x",t=>t.normalize("NFKC")]].filter(([e])=>t.includes(e)).map(([,t])=>t),s=t=>r.reduce((t,e)=>e(t),t);return d.pipeline.set(t,s),s}static normalize(t,e){if(!e||"string"!=typeof e||!t)return t;if(e=this.canonicalFlags(e),Array.isArray(t))return t.map(t=>d.normalize(t,e));const r=d.cache.key(e,[t]);if(r&&d.cache.has(r))return d.cache.get(r);const s=d.getPipeline(e)(t);return r&&d.cache.set(r,s),s}static async normalizeAsync(t,e){return await(Array.isArray(t)?Promise.all(t.map(t=>d.normalize(t,e))):Promise.resolve(d.normalize(t,e)))}static clear(){d.pipeline.clear(),d.cache.clear()}}class g{active;static ENV;static instance;nowFn;memFn;store=new Set;totalTime=0;totalMem=0;static detectEnv(){"undefined"!=typeof process?g.ENV="nodejs":"undefined"!=typeof performance?g.ENV="browser":g.ENV="unknown"}static getInstance(t){return g.ENV||g.detectEnv(),g.instance||=new g(t)}constructor(t=!1){switch(this.active=t,g.ENV){case"nodejs":this.nowFn=()=>Number(process.hrtime.bigint())/1e6,this.memFn=()=>process.memoryUsage().heapUsed;break;case"browser":this.nowFn=()=>performance.now(),this.memFn=()=>performance.memory?.usedJSHeapSize??0;break;default:this.nowFn=()=>Date.now(),this.memFn=()=>0}}now=()=>this.nowFn();mem=()=>this.memFn();profile(t,e){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}enable=()=>{this.active=!0};disable=()=>{this.active=!1};clear(){this.store.clear(),this.totalTime=0,this.totalMem=0}run(t,e={}){return this.active?this.profile(t,e):t()}async runAsync(t,e={}){return this.active?this.profile(async()=>await t(),e):await t()}getAll=()=>[...this.store];getLast=()=>this.getAll().pop();getTotal=()=>({time:this.totalTime,mem:this.totalMem});services=Object.freeze({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)})}const m=Object.create(null),f=Object.create(null);function y(t,e){if(t in m||t in f)throw new Error(`Registry <${t}> already exists / overwriting is forbidden`);const r=Object.create(null),s=Object.freeze({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 m[t]=s,f[t]=(e,...r)=>function(t,e,...r){e=function(t,e){if(!(t in m))throw new ReferenceError(`Registry <${t}> does not exist`);return"string"==typeof e?m[t]?.get(e):e}(t,e);try{return new e(...r)}catch(t){throw new Error(`Cannot instantiate class <${e.name??e}>`,{cause:t})}}(t,e,...r),s}class w{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-1,i=this.buffers[n];if(i.size>=t&&(e||i.size===t))return this.pointer=n+1&r-1,i}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 b{static CONFIG={int32:{type:"int32",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={int32:new w(64),"number[]":new w(16),"string[]":new w(2),set:new w(8),map:new w(8)};static allocate(t,e){switch(t){case"int32":return new Int32Array(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?"int32"===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 A{data;key;static create(t,e){return new A(t,e)}constructor(t,e){this.data=t,this.key=e}extractFrom(t,e){const r=b.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=()=>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=[];if(this.isMetricResult(e))r=t;else{if(!this.isCmpStrResult(e))throw new TypeError("Unsupported result format for StructuredData normalization.");r=t.map(t=>({metric:"unknown",a:t.source,b:t.target,res:t.match,raw:t.raw}))}return 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 p=h.b||"",u=i.get(p);let d;if(u&&u.length>0){const t=o.get(p)??0;o.set(p,t+1),d=u[t%u.length]}else d=h.__idx??l;if(d<0||d>=e.length)continue;const g=e[d],m=r[d]||p;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)}finalizeLookup(t,e,r){return this.rebuild(this.sort(this.normalizeResults(t),r?.sort),this.data,e,r?.removeZero,r?.objectsOnly)}performLookup(t,e,r){return this.finalizeLookup(t(),e,r)}async performLookupAsync(t,e,r){return this.finalizeLookup(await t(),e,r)}lookup(t,e,r){const s=this.extract();try{return this.performLookup(()=>t(e,s,r),s,r)}finally{b.release("string[]",s,s.length)}}async lookupAsync(t,e,r){const s=this.extract();try{return await this.performLookupAsync(()=>t(e,s,r),s,r)}finally{b.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{b.release("string[]",n,n.length),b.release("string[]",i,i.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{b.release("string[]",n,n.length),b.release("string[]",i,i.length)}}}class x{static REGEX={number:/\d/,sentence:/(?<=[.!?])\s+/,word:/\p{L}+/gu,nonWord:/[^\p{L}]/gu,vowelGroup:/[aeiouy]+/g,letter:/\p{L}/gu,ucLetter:/\p{Lu}/gu};text;words=[];sentences=[];charFrequency=new Map;wordHistogram=new Map;syllableCache=new Map;syllableStats;constructor(t){this.text=t.trim(),this.tokenize(),this.computeFrequencies()}tokenize(){let t;const e=this.text.toLowerCase();for(;null!==(t=x.REGEX.word.exec(e));)this.words.push(t[0]);this.sentences=this.text.split(x.REGEX.sentence).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){const e=t.normalize("NFC").toLowerCase().replace(x.REGEX.nonWord,"");if(this.syllableCache.has(e))return this.syllableCache.get(e);const r=e.match(x.REGEX.vowelGroup),s=r?r.length:1;return this.syllableCache.set(e,s),s}computeSyllableStats(){return this.syllableStats||=(()=>{const t=this.words.map(t=>this.estimateSyllables(t)).sort((t,e)=>t-e),e=t.reduce((t,e)=>t+e,0),r=t.filter(t=>1===t).length,s=t.length?t.length%2==0?(t[t.length/2-1]+t[t.length/2])/2:t[Math.floor(t.length/2)]:0;return{total:e,mono:r,perWord:t,avg:t.length?e/t.length:0,median:s}})()}getLength=()=>this.text.length;getWordCount=()=>this.words.length;getSentenceCount=()=>this.sentences.length;getAvgWordLength(){return this.words.length?this.words.join("").length/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=()=>x.REGEX.number.test(this.text);getUpperCaseRatio(){const t=this.text.match(x.REGEX.letter)||[],e=this.text.match(x.REGEX.ucLetter)?.length||0;return t.length?e/t.length:0}getCharFrequency(){return Object.fromEntries(this.charFrequency)}getUnicodeCodepoints(){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(){return this.computeSyllableStats().total}getMonosyllabicWordCount(){return this.computeSyllableStats().mono}getMinSyllablesWordCount(t){return this.computeSyllableStats().perWord.filter(e=>e>=t).length}getMaxSyllablesWordCount(t){return this.computeSyllableStats().perWord.filter(e=>e<=t).length}getAvgSyllablesPerWord(){return this.computeSyllableStats().avg}getMedianSyllablesPerWord(){return this.computeSyllableStats().median}getHonoresR(){try{return 100*Math.log(this.words.length)/(1-this.getHapaxLegomena().length/(this.wordHistogram.size??1))}catch{return 0}}getReadingTime(t=200){return 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]}}const S=g.getInstance();class v{static cache=new u;metric;a;b;origA=[];origB=[];options;optKey;symmetric;results;static clear=()=>this.cache.clear();static swap=(t,e,r,s)=>r>s?[e,t,s,r]:[t,e,r,s];static clamp=t=>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.optKey=p.fastFNV1a(JSON.stringify(s,Object.keys(s).sort())).toString(),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=S.run(()=>{this.symmetric&&([s,i,a,o]=v.swap(s,i,a,o));const t=v.cache.key(this.metric,[s,i],this.symmetric)+this.optKey;return v.cache.get(t||"")??(()=>{const e=this.compute(s,i,a,o,Math.max(a,o));return t&&v.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=()=>this.a.length>1||this.b.length>1;isSingle=()=>!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=()=>this.symmetric;whichMode=t=>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=()=>this.metric;getResults(){if(void 0===this.results)throw new Error("run() must be called before getResult()");return this.results}}const z=y("metric",v);z.add("cosine",class extends v{constructor(t,e,r={}){super("cosine",t,e,r,!0)}_termFreq(t,e){const r=t.split(e),s=b.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);try{let t=0,e=0,r=0;for(const[r,i]of s)t+=i*(n.get(r)||0),e+=i*i;for(const t of n.values())r+=t*t;return e=Math.sqrt(e),r=Math.sqrt(r),{res:e&&r?v.clamp(t/(e*r)):0,raw:{dotProduct:t,magnitudeA:e,magnitudeB:r}}}finally{b.release("map",s,s.size),b.release("map",n,n.size)}}}),z.add("damerau",class extends v{constructor(t,e,r={}){super("damerau",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o,c]=b.acquireMany("int32",[i,i,i]);try{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 i=o[r];return{res:0===n?1:v.clamp(1-i/n),raw:{dist:i,maxLen:n}}}finally{b.release("int32",a,i),b.release("int32",o,i),b.release("int32",c,i)}}}),z.add("dice",class extends v{constructor(t,e,r={}){super("dice",t,e,r,!0)}_bigrams(t){const e=t.length-1,r=b.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),n=r.size,i=s.size;try{let t=0;for(const e of r)s.has(e)&&t++;const e=n+i;return{res:0===e?1:v.clamp(2*t/e),raw:{intersection:t,size:e}}}finally{b.release("set",r,n),b.release("set",s,i)}}}),z.add("hamming",class extends v{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 s=0;s<r;s++)t[s]!==e[s]&&i++;return{res:0===r?1:v.clamp(1-i/r),raw:{dist:i}}}}),z.add("jaccard",class extends v{constructor(t,e,r={}){super("jaccard",t,e,r,!0)}compute(t,e,r,s){const[n,i]=b.acquireMany("set",[r,s]);try{for(const e of t)n.add(e);for(const t of e)i.add(t);let r=0;for(const t of n)i.has(t)&&r++;const s=n.size+i.size-r;return{res:0===s?1:v.clamp(r/s),raw:{intersection:r,union:s}}}finally{b.release("set",n,r),b.release("set",i,s)}}}),z.add("jaroWinkler",class extends v{constructor(t,e,r={}){super("jaroWinkler",t,e,r,!0)}compute(t,e,r,s){const[n,i]=b.acquireMany("int32",[r,s]);try{for(let t=0;t<r;t++)n[t]=0;for(let t=0;t<s;t++)i[t]=0;const a=Math.max(0,Math.floor(s/2)-1);let o=0;for(let c=0;c<r;c++){const r=Math.max(0,c-a),l=Math.min(c+a+1,s);for(let s=r;s<l;s++)if(!i[s]&&t[c]===e[s]){n[c]=1,i[s]=1,o++;break}}let c=0,l=0,h=0,p=0;if(o>0){let a=0;for(let s=0;s<r;s++)if(n[s]){for(;!i[a];)a++;t[s]!==e[a]&&c++,a++}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++;p=l+.1*h*(1-l)}return{res:v.clamp(p),raw:{matchWindow:a,matches:o,transpos:c,jaro:l,prefix:h}}}finally{b.release("int32",n,r),b.release("int32",i,s)}}}),z.add("lcs",class extends v{constructor(t,e,r={}){super("lcs",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o]=b.acquireMany("int32",[i,i]);try{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 i=a[r];return{res:0===n?1:v.clamp(i/n),raw:{lcs:i,maxLen:n}}}finally{b.release("int32",a,i),b.release("int32",o,i)}}}),z.add("levenshtein",class extends v{constructor(t,e,r={}){super("levenshtein",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o]=b.acquireMany("int32",[i,i]);try{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 i=a[r];return{res:0===n?1:v.clamp(1-i/n),raw:{dist:i,maxLen:n}}}finally{b.release("int32",a,i),b.release("int32",o,i)}}}),z.add("needlemanWunsch",class extends v{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]=b.acquireMany("int32",[c,c]);try{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 c=l[r],p=n*i;return{res:0===p?0:v.clamp(c/p),raw:{score:c,denum:p}}}finally{b.release("int32",l,c),b.release("int32",h,c)}}}),z.add("qGram",class extends v{constructor(t,e,r={}){super("qGram",t,e,r,!0)}_qGrams(t,e){const r=Math.max(0,t.length-e+1),s=b.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),i=s.size,a=n.size;try{let t=0;for(const e of s)n.has(e)&&t++;const e=Math.max(i,a);return{res:0===e?1:v.clamp(t/e),raw:{intersection:t,size:e}}}finally{b.release("set",s,i),b.release("set",n,a)}}}),z.add("smithWaterman",class extends v{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]=b.acquireMany("int32",[o,o]);let h=0;try{for(let t=0;t<=r;t++)c[t]=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)}const o=Math.min(r*n,s*n);return{res:0===o?0:v.clamp(h/o),raw:{score:h,denum:o}}}finally{b.release("int32",c,o),b.release("int32",l,o)}}});const k=g.getInstance();class M{static cache=new u;static default;algo;options;optKey;map;static clear=()=>this.cache.clear();constructor(t,e={}){const r=this.constructor.default??{},s=e.map??r.map;if(!s)throw new Error("No mapping specified for phonetic algorithm");const n=E.get(t,s);if(void 0===n)throw new Error(`Requested mapping <${s}> is not declared`);this.options=a(a(r,n.options??{}),e),this.optKey=p.fastFNV1a(JSON.stringify(this.options,Object.keys(this.options).sort())).toString(),this.algo=t,this.map=n}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||0!==e&&e!==s-1)&&("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=>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=M.cache.key(this.algo,[r])+this.optKey,s=M.cache.get(t||"")??(()=>{const e=this.encode(r);return t&&M.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=M.cache.key(this.algo,[r])+this.optKey,s=await Promise.resolve(M.cache.get(t||"")??(()=>{const e=this.encode(r);return t&&M.cache.set(t,e),e})());s&&s.length&&e.push(this.equalLen(s))}return e}getAlgoName=()=>this.algo;getIndex(t){const{delimiter:e=" "}=this.options;return k.run(()=>this.loop(t.split(e).filter(Boolean)).filter(Boolean))}async getIndexAsync(t){const{delimiter:e=" "}=this.options;return(await k.runAsync(async()=>await this.loopAsync(t.split(e).filter(Boolean)))).filter(Boolean)}}const C=y("phonetic",M),E=(()=>{const t=Object.create(null),e=e=>t[e]||=Object.create(null);return Object.freeze({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))})})();class O extends M{static REGEX={uppercase:/[^A-Z]/gi};static default={map:"en2",delimiter:" ",length:-1,pad:"",dedupe:!1};constructor(t={}){super("caverphone",t)}encode(t){return t=t.replace(O.REGEX.uppercase,"").toLowerCase(),super.encode(t)}mapChar=t=>t;adjustCode=t=>t.toUpperCase()}C.add("caverphone",O),E.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:""}]}),E.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:""}]}),C.add("cologne",class extends M{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","")}}),E.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"}]});class j extends M{static REGEX={adjacent:/([A-BD-Z])\1+/gi,vowel:/[AEIOU]/g};static default={map:"en90",delimiter:" ",length:-1,pad:"",dedupe:!1};constructor(t={}){super("metaphone",t)}encode(t){return t=t.replace(j.REGEX.adjacent,(t,e)=>"C"===e?t:e),super.encode(t)}adjustCode(t){return t.slice(0,1)+t.slice(1).replace(j.REGEX.vowel,"")}}C.add("metaphone",j),E.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:""}]}),C.add("soundex",class extends M{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","")}}),E.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"}}),E.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 L=g.getInstance();class N{static filter={has:h.has,add:h.add,remove:h.remove,pause:h.pause,resume:h.resume,list:h.list,clear:h.clear};static metric={add:z.add,remove:z.remove,has:z.has,list:z.list};static phonetic={add:C.add,remove:C.remove,has:C.has,list:C.list,map:{add:E.add,remove:E.remove,has:E.has,list:E.list}};static profiler=L.services;static clearCache={normalizer:d.clear,metric:v.clear,phonetic:M.clear};static analyze=t=>new x(t);static diff=(t,e,r)=>new l(t,e,r);static create(t){return new N(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(!N.metric.has(e))throw new Error("CmpStr <metric> must be set, call .setMetric(), use CmpStr.metric.list() for available metrics");break;case"phonetic":if(!N.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 a({...this.options??Object.create(null)},t)}normalize(t,e){return d.normalize(t,e??this.options.flags??"")}filter(t,e){return h.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=f.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 A.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=f.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=()=>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 a(this.options,t),this}setSerializedOptions(t){return this.options=JSON.parse(t),this}setOption(t,e){return i(this.options,t,e),this}rmvOption(t){return o(this.options,t),this}setRaw=t=>this.setOption("raw",t);setMetric=t=>this.setOption("metric",t);setFlags=t=>this.setOption("flags",t);rmvFlags=()=>this.rmvOption("flags");setProcessors=t=>this.setOption("processors",t);rmvProcessors=()=>this.rmvOption("processors");getOptions=()=>this.options;getSerializedOptions=()=>JSON.stringify(this.options);getOption=t=>n(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 F extends N{static create(t){return new F(t)}constructor(t){super(t)}async normalizeAsync(t,e){return d.normalizeAsync(t,e??this.options.flags??"")}async filterAsync(t,e){return h.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=f.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=f.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)}}t.CmpStr=N,t.CmpStrAsync=F,t.DeepMerge=c,t.DiffChecker=l,t.Filter=h,t.HashTable=u,t.Hasher=p,t.Metric=v,t.MetricRegistry=z,t.Normalizer=d,t.Phonetic=M,t.PhoneticMappingRegistry=E,t.PhoneticRegistry=C,t.Pool=b,t.Profiler=g,t.StructuredData=A,t.TextAnalyzer=x});
8
- //# sourceMappingURL=CmpStr.umd.min.js.map
7
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CmpStr={})}(this,function(t){"use strict";class e extends Error{code;meta;cause;when=(new Date).toISOString();constructor(t,e,s,r){super(e),this.name=this.constructor.name,this.code=t,this.meta=s,this.cause=r,"function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,code:this.code,message:this.message,meta:this.meta,when:this.when,cause:this.cause instanceof Error?{name:this.cause.name,message:this.cause.message,stack:this.cause.stack}:this.cause}}toString(t=!1){const e=[`${this.name} [${this.code}]`,this.message];if(this.meta&&Object.keys(this.meta).length)try{e.push(JSON.stringify(this.meta))}catch{}return e.join(" - ")+(t&&this.stack?`\nStack Trace:\n${this.stack}`:"")}}class s extends e{constructor(t,e,s){super("E_VALIDATION",t,e,s)}}class r extends e{constructor(t,e,s){super("E_NOT_FOUND",t,e,s)}}class n extends e{constructor(t,e,s){super("E_USAGE",t,e,s)}}class i extends e{constructor(t,e,s){super("E_INTERNAL",t,e,s)}}class a{static assert(t,e,s){if(!t)throw new n(e,s)}static create(t,s,r){if(t instanceof e)throw t;throw new i(s,r,t)}static format(t){return t instanceof e?t.toString():t instanceof Error?`${t.name}: ${t.message}`:String(t)}static wrap(t,e,s){try{return t()}catch(t){throw new i(e,s,t)}}static async wrapAsync(t,e,s){try{return await t()}catch(t){throw new i(e,s,t)}}}var o=Object.freeze({__proto__:null,CmpStrError:e,CmpStrInternalError:i,CmpStrNotFoundError:r,CmpStrUsageError:n,CmpStrValidationError:s,ErrorUtil:a});const c=/\[(\d+)]/g,l=new Map;function h(t){let e=l.get(t);if(e)return e;const s=t.replace(c,".$1").split(".").map(t=>{const e=Number(t);return Number.isInteger(e)&&String(e)===t?e:t});return l.set(t,s),s}function p(t,e,s){let r=t;for(const t of h(e)){if(null==r||!(t in r))return s;r=r[t]}return r}function u(t,e,s){if(""===e)return s;const r=h(e);if(void 0!==t&&("object"!=typeof t||null===t))throw new n(`Cannot set property <${r[0]}> of <${JSON.stringify(t)}>`,{path:r[0],target:t});const i=t??("number"==typeof r[0]?[]:Object.create(null));let a=i;for(let t=0;t<r.length-1;t++){const e=r[t];let s=a[e];if(null!=s&&"object"!=typeof s)throw new n(`Cannot set property <${r[t+1]}> of <${JSON.stringify(s)}>`,{path:r.slice(0,t+2),value:s});null==s&&(s=a[e]="number"==typeof r[t+1]?[]:Object.create(null)),a=s}return a[r[r.length-1]]=s,i}function d(t=Object.create(null),e=Object.create(null),s=!1){const r=t??Object.create(null);return Object.keys(e).forEach(t=>{const n=e[t];if((s||void 0!==n)&&"__proto__"!==t&&"constructor"!==t)if(null===n||"object"!=typeof n||Array.isArray(n))r[t]=n;else{const e=r[t];r[t]=d(null===e||"object"!=typeof e||Array.isArray(e)?Object.create(null):e,n,s)}}),r}function g(t,e,s=!1){const r=h(e),n=(t,e=0)=>{const i=r[e];if(!t||"object"!=typeof t)return!1;if(e===r.length-1)return delete t[i];if(!n(t[i],e+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(t),t}var m=Object.freeze({__proto__:null,get:p,has:function(t,e){let s=t;for(const t of h(e)){if(null==s||!(t in s))return!1;s=s[t]}return!0},merge:d,rmv:g,set:u});class f{a;b;options;entries=[];grouped=[];diffRun=!1;constructor(t,e,s={}){this.a=t,this.b=e,this.options={mode:"word",caseInsensitive:!1,contextLines:1,groupedLines:!0,expandLines:!1,showChangeMagnitude:!0,maxMagnitudeSymbols:5,lineBreak:"\n",...s},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){switch(this.options.mode){case"line":return[t];case"word":return t.split(/\s+/)}}concat(t){return t.join("word"===this.options.mode?" ":"")}computeDiff(){if(this.diffRun)return;const{linesA:t,linesB:e,maxLen:s}=this.text2lines();for(let r=0;r<s;r++)this.lineDiff(t[r]||"",e[r]||"",r);this.findGroups(),this.diffRun=!0}lineDiff(t,e,s){const{mode:r,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;switch(r){case"line":a!==o&&(c.push({posA:0,posB:0,del:t,ins:e,size:e.length-t.length}),l=t.length,h=e.length);break;case"word":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:s,diffs:c,delSize:l,insSize:h,baseLen:i,totalSize:h-l,magnitude:this.magnitude(l,h,i)})}preciseDiff(t,e,s,r){const n=t=>t.reduce((e,s,r)=>(e.push(r?e[r-1]+t[r-1].length+1:0),e),[]),i=this.tokenize(t),a=this.tokenize(s),o=this.tokenize(e),c=this.tokenize(r),l=o.length,h=c.length,p=n(i),u=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),s=a.slice(w,t.bi);f.push({posA:p[y]??0,posB:u[w]??0,del:this.concat(e),ins:this.concat(s),size:s.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:p[y]??0,posB:u[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,s)=>{const[r,n,i,a]=["delSize","insSize","totalSize","baseLen"].map(e=>t.reduce((t,s)=>t+s[e],0));this.grouped.push({start:e,end:s,delSize:r,insSize:n,totalSize:i,line:t[0].line,entries:t,magnitude:this.magnitude(r,n,a)})};let s=[],r=0,n=0;for(const i of this.entries){const a=Math.max(0,i.line-t),o=i.line+t;!s.length||a<=n+1?(s.length||(r=a),n=Math.max(n,o),s.push(i)):(e(s,r,n),s=[i],r=a,n=o)}s.length&&e(s,r,n)}magnitude(t,e,s){const{maxMagnitudeSymbols:r}=this.options,n=t+e;if(0===n||0===s)return"";const i=Math.min(r,Math.max(Math.round(n/s*r),1)),a=Math.round(e/n*i),o=i-a;return"+".repeat(a)+"-".repeat(o)}output(t){const{mode:e,contextLines:s,groupedLines:r,expandLines:n,showChangeMagnitude:i,lineBreak:a}=this.options,{linesA:o,linesB:c,maxLen:l}=this.text2lines(),h=Math.max(4,l.toString().length),p=(e,s)=>t?`[${s}m${e}`:e,u=e=>t?`${e}`:`-[${e}]`,d=e=>t?`${e}`:`+[${e}]`,g=(t,e,s,r)=>{r&&m(r);for(let r=t;r<=e;r++)f(r,s??r);w.push("")},m=t=>{var e;w.push(`${" ".repeat(h)} ${e=`@@ -${t.line+1},${t.delSize} +${t.line+1},${t.insSize} @@`,p(e,"36")} ${i?(t=>p(t,"33"))(t.magnitude):""}`)},f=(t,e)=>{if(o[t]||c[t]){const r=this.entries.find(e=>e.line===t),n=(t+1).toString().padStart(h," ");r&&e===t?(w.push(`${n} ${s=`- ${y(o[t],r.diffs,"del")}`,p(s,"31")}`),w.push(`${" ".repeat(h)} ${(t=>p(t,"32"))(`+ ${y(c[t],r.diffs,"ins")}`)}`)):w.push(`${n} ${(t=>p(t,"90"))(o[t])}`)}var s},y=(t,s,r)=>{if(!s.length||"line"===e)return t;let n="",i=0;for(const e of s){const s="del"===r?e.posA:e.posB,a="del"===r?e.del:e.ins;a&&(s>i&&(n+=t.slice(i,s)),n+="del"===r?u(a):d(a),i=s+a.length)}return n+t.slice(i)};let w=[""];switch(!0){case n:g(0,l);break;case r: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-s,t.line+s,t.line,t)}return w.join(a)}getStructuredDiff=()=>this.entries;getGroupedDiff=()=>this.grouped;getASCIIDiff=()=>this.output(!1);getCLIDiff=()=>this.output(!0)}class y{static filters=new Map;static pipeline=new Map;static getPipeline(t){return a.wrap(()=>{const e=y.pipeline.get(t);if(e)return e;const s=y.filters.get(t);if(!s)return t=>t;const r=Array.from(s.values()).filter(t=>t.active).sort((t,e)=>t.priority-e.priority).map(t=>t.fn),n=t=>r.reduce((t,e)=>e(t),t);return y.pipeline.set(t,n),n},`Error compiling filter pipeline for hook <${t}>`,{hook:t})}static has(t,e){return!!y.filters.get(t)?.has(e)}static add(t,e,s,r={}){return a.wrap(()=>{const{priority:n=10,active:i=!0,overrideable:a=!0}=r,o=y.filters.get(t)??new Map,c=o.get(e);return!(c&&!c.overrideable||(o.set(e,{id:e,fn:s,priority:n,active:i,overrideable:a}),y.filters.set(t,o),y.pipeline.delete(t),0))},`Error adding filter <${e}> to hook <${t}>`,{hook:t,id:e,opt:r})}static remove(t,e){y.pipeline.delete(t);const s=y.filters.get(t);return!!s&&s.delete(e)}static pause(t,e){y.pipeline.delete(t);const s=y.filters.get(t)?.get(e);return!(!s||(s.active=!1,0))}static resume(t,e){y.pipeline.delete(t);const s=y.filters.get(t)?.get(e);return!(!s||(s.active=!0,0))}static list(t,e=!1){const s=y.filters.get(t);if(!s)return[];const r=[];for(const t of s.values())e&&!t.active||r.push(t.id);return r}static apply(t,e){return a.wrap(()=>{const s=y.getPipeline(t);return Array.isArray(e)?e.map(s):s(e)},`Error applying filters for hook <${t}>`,{hook:t,input:e})}static async applyAsync(t,e){return a.wrapAsync(async()=>{const s=y.getPipeline(t);return Array.isArray(e)?Promise.all(e.map(s)):Promise.resolve(s(e))},`Error applying filters for hook <${t}>`,{hook:t,input:e})}static clear(t){y.pipeline.clear(),t?y.filters.delete(t):y.filters.clear()}static clearPipeline(){y.pipeline.clear()}}class w{static FNV_PRIME=16777619;static HASH_OFFSET=2166136261;static fastFNV1a(t){const e=t.length;let s=this.HASH_OFFSET;const r=Math.floor(e/4);for(let e=0;e<r;e++){const r=4*e;s^=t.charCodeAt(r)|t.charCodeAt(r+1)<<8|t.charCodeAt(r+2)<<16|t.charCodeAt(r+3)<<24,s=Math.imul(s,this.FNV_PRIME)}const n=e%4;if(n>0){const e=4*r;for(let r=0;r<n;r++)s^=t.charCodeAt(e+r),s=Math.imul(s,this.FNV_PRIME)}return s^=s>>>16,s*=2246822507,s^=s>>>13,s*=3266489909,s^=s>>>16,s>>>0}}class b{LRU;static MAX_LEN=2048;static TABLE_SIZE=1e4;table=new Map;constructor(t=!0){this.LRU=t}key(t,e,s=!1){for(const t of e)if(t.length>b.MAX_LEN)return!1;const r=e.map(t=>w.fastFNV1a(t));return[t,...s?r.sort():r].join("-")}has=t=>this.table.has(t);get=t=>this.table.get(t);set(t,e,s=!0){if(!s&&this.table.has(t))return!1;for(;!this.table.has(t)&&this.table.size>=b.TABLE_SIZE;){if(!this.LRU)return!1;this.table.delete(this.table.keys().next().value)}return this.table.set(t,e),!0}delete=t=>this.table.delete(t);clear=()=>this.table.clear();size=()=>this.table.size}class A{static pipeline=new Map;static cache=new b;static REGEX={whitespace:/\s+/g,doubleChars:/(.)\1+/g,specialChars:/[^\p{L}\p{N}\s]/gu,nonLetters:/[^\p{L}]/gu,nonNumbers:/\p{N}/gu};static canonicalFlags(t){return Array.from(new Set(t)).sort().join("")}static getPipeline(t){return a.wrap(()=>{if(A.pipeline.has(t))return A.pipeline.get(t);const{REGEX:e}=A,s=[["d",t=>t.normalize("NFD")],["i",t=>t.toLowerCase()],["k",t=>t.replace(e.nonLetters,"")],["n",t=>t.replace(e.nonNumbers,"")],["r",t=>t.replace(e.doubleChars,"$1")],["s",t=>t.replace(e.specialChars,"")],["t",t=>t.trim()],["u",t=>t.normalize("NFC")],["w",t=>t.replace(e.whitespace," ")],["x",t=>t.normalize("NFKC")]].filter(([e])=>t.includes(e)).map(([,t])=>t),r=t=>s.reduce((t,e)=>e(t),t);return A.pipeline.set(t,r),r},`Failed to create normalization pipeline for flags: ${t}`,{flags:t})}static normalize(t,e){return a.wrap(()=>{if(!e||"string"!=typeof e||!t)return t;if(e=this.canonicalFlags(e),Array.isArray(t))return t.map(t=>A.normalize(t,e));const s=A.cache.key(e,[t]);if(s&&A.cache.has(s))return A.cache.get(s);const r=A.getPipeline(e)(t);return s&&A.cache.set(s,r),r},`Failed to normalize input with flags: ${e}`,{input:t,flags:e})}static async normalizeAsync(t,e){return await a.wrapAsync(async()=>e&&"string"==typeof e&&t?await(Array.isArray(t)?Promise.all(t.map(t=>A.normalize(t,e))):Promise.resolve(A.normalize(t,e))):t,`Failed to asynchronously normalize input with flags: ${e}`,{input:t,flags:e})}static clear(){A.pipeline.clear(),A.cache.clear()}}class x{active;static ENV;static instance;nowFn;memFn;store=new Set;totalTime=0;totalMem=0;static detectEnv(){"undefined"!=typeof process?x.ENV="nodejs":"undefined"!=typeof performance?x.ENV="browser":x.ENV="unknown"}static getInstance(t){return x.ENV||x.detectEnv(),x.instance||=new x(t)}constructor(t=!1){switch(this.active=t,x.ENV){case"nodejs":this.nowFn=()=>Number(process.hrtime.bigint())/1e6,this.memFn=()=>process.memoryUsage().heapUsed;break;case"browser":this.nowFn=()=>performance.now(),this.memFn=()=>performance.memory?.usedJSHeapSize??0;break;default:this.nowFn=()=>Date.now(),this.memFn=()=>0}}now=()=>this.nowFn();mem=()=>this.memFn();profile(t,e){const s=this.now(),r=this.mem(),n=t(),i=this.now()-s,a=this.mem()-r;return this.store.add({time:i,mem:a,res:n,meta:e}),this.totalTime+=i,this.totalMem+=a,n}enable=()=>{this.active=!0};disable=()=>{this.active=!1};clear(){this.store.clear(),this.totalTime=0,this.totalMem=0}run(t,e={}){return this.active?this.profile(t,e):t()}async runAsync(t,e={}){return this.active?this.profile(async()=>await t(),e):await t()}getAll=()=>[...this.store];getLast=()=>this.getAll().pop();getTotal=()=>({time:this.totalTime,mem:this.totalMem});services=Object.freeze({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)})}const S=Object.create(null),v=Object.create(null);function k(t,e){a.assert(!(t in S||t in v),`Registry <${t}> already exists / overwriting is forbidden`,{registry:t});const s=Object.create(null),n=Object.freeze({add(r,n,i=!1){a.assert("string"==typeof r&&r.length>0,"Class name must be a non-empty string",{registry:t,name:r}),a.assert("function"==typeof n,"Class must be a constructor function",{registry:t,class:n}),a.assert(n.prototype instanceof e,`Class must extend <${t}>`,{registry:t,class:n}),a.assert(i||!(r in s),`Class <${r}> already exists / use <update=true> to overwrite`,{registry:t,name:r}),s[r]=n},remove(t){delete s[t]},has:t=>t in s,list:()=>Object.keys(s),get:e=>(a.assert("string"==typeof e&&e.length>0,"Class name must be a non-empty string",{registry:t,name:e}),a.assert(e in s,`Class <${e}> not registered for <${t}>`,{registry:t,name:e}),s[e])});return S[t]=n,v[t]=(e,...s)=>function(t,e,...s){return e=function(t,e){if(!(t in S))throw new r(`Registry <${t}> does not exist`,{registry:t});return"string"==typeof e?S[t]?.get(e):e}(t,e),a.wrap(()=>new e(...s),`Failed to create instance of class <${e.name??e}> from registry <${t}>`,{registry:t,class:e,args:s})}(t,e,...s),n}class z{maxSize;buffers=[];pointer=0;constructor(t){this.maxSize=t}acquire(t,e){return a.wrap(()=>{const s=this.buffers.length;for(let r=0;r<s;r++){const n=this.pointer+r&s-1,i=this.buffers[n];if(i.size>=t&&(e||i.size===t))return this.pointer=n+1&s-1,i}return null},`Failed to acquire buffer of size >= ${t} from pool`,{minSize:t,allowOversize:e})}release(t){a.wrap(()=>{this.buffers.length<this.maxSize?this.buffers.push(t):(this.buffers[this.pointer]=t,this.pointer=(this.pointer+1)%this.maxSize)},"Failed to release buffer back to pool",{item:t})}clear(){this.buffers=[],this.pointer=0}}class C{static CONFIG={int32:{type:"int32",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={int32:new z(64),"number[]":new z(16),"string[]":new z(2),set:new z(8),map:new z(8)};static allocate(t,e){switch(t){case"int32":return new Int32Array(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 s=this.CONFIG[t];if(!s)throw new n(`Unsupported pool type <${t}>`,{type:t});if(e>s.maxItemSize)return this.allocate(t,e);const r=this.POOLS[t].acquire(e,s.allowOversize);return r?"int32"===t?r.buffer.subarray(0,e):r.buffer:this.allocate(t,e)}static acquireMany(t,e){return e.map(e=>this.acquire(t,e))}static release(t,e,s){const r=this.CONFIG[t];if(!r)throw new n(`Unsupported pool type <${t}>`,{type:t});s<=r.maxItemSize&&this.POOLS[t].release({buffer:e,size:s})}}class M{data;key;static create(t,e){return new M(t,e)}constructor(t,e){this.data=t,this.key=e}extractFrom(t,e){const s=C.acquire("string[]",t.length);for(let r=0;r<t.length;r++){const n=t[r][e];s[r]="string"==typeof n?n:String(n??"")}return s}extract=()=>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=[];if(this.isMetricResult(e))r=t;else{if(!this.isCmpStrResult(e))throw new s("Unsupported result format for StructuredData normalization.");r=t.map(t=>({metric:"unknown",a:t.source,b:t.target,res:t.match,raw:t.raw}))}return r.map((t,e)=>({...t,__idx:e}))}rebuild(t,e,s,r,n){const i=new Map;for(let t=0;t<s.length;t++){const e=s[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(r&&0===h.res)continue;const p=h.b||"",u=i.get(p);let d;if(u&&u.length>0){const t=o.get(p)??0;o.set(p,t+1),d=u[t%u.length]}else d=h.__idx??l;if(d<0||d>=e.length)continue;const g=e[d],m=s[d]||p;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 s="asc"===e;return t.sort((t,e)=>s?t.res-e.res:e.res-t.res)}finalizeLookup(t,e,s){return this.rebuild(this.sort(this.normalizeResults(t),s?.sort),this.data,e,s?.removeZero,s?.objectsOnly)}performLookup(t,e,s){return a.wrap(()=>this.finalizeLookup(t(),e,s),"StructuredData lookup failed",{key:this.key})}async performLookupAsync(t,e,s){return await a.wrapAsync(async()=>this.finalizeLookup(await t(),e,s),"StructuredData async lookup failed",{key:this.key})}lookup(t,e,s){const r=this.extract();try{return this.performLookup(()=>t(e,r,s),r,s)}finally{C.release("string[]",r,r.length)}}async lookupAsync(t,e,s){const r=this.extract();try{return await this.performLookupAsync(()=>t(e,r,s),r,s)}finally{C.release("string[]",r,r.length)}}lookupPairs(t,e,s,r){const n=this.extract(),i=this.extractFrom(e,s);try{return this.performLookup(()=>t(n,i,r),n,r)}finally{C.release("string[]",n,n.length),C.release("string[]",i,i.length)}}async lookupPairsAsync(t,e,s,r){const n=this.extract(),i=this.extractFrom(e,s);try{return await this.performLookupAsync(()=>t(n,i,r),n,r)}finally{C.release("string[]",n,n.length),C.release("string[]",i,i.length)}}}class O{static REGEX={number:/\d/,sentence:/(?<=[.!?])\s+/,word:/\p{L}+/gu,nonWord:/[^\p{L}]/gu,vowelGroup:/[aeiouy]+/g,letter:/\p{L}/gu,ucLetter:/\p{Lu}/gu};text;words=[];sentences=[];charFrequency=new Map;wordHistogram=new Map;syllableCache=new Map;syllableStats;constructor(t){this.text=t.trim(),this.tokenize(),this.computeFrequencies()}tokenize(){let t;const e=this.text.toLowerCase();for(;null!==(t=O.REGEX.word.exec(e));)this.words.push(t[0]);this.sentences=this.text.split(O.REGEX.sentence).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){const e=t.normalize("NFC").toLowerCase().replace(O.REGEX.nonWord,"");if(this.syllableCache.has(e))return this.syllableCache.get(e);const s=e.match(O.REGEX.vowelGroup),r=s?s.length:1;return this.syllableCache.set(e,r),r}computeSyllableStats(){return this.syllableStats||=(()=>{const t=this.words.map(t=>this.estimateSyllables(t)).sort((t,e)=>t-e),e=t.reduce((t,e)=>t+e,0),s=t.filter(t=>1===t).length,r=t.length?t.length%2==0?(t[t.length/2-1]+t[t.length/2])/2:t[Math.floor(t.length/2)]:0;return{total:e,mono:s,perWord:t,avg:t.length?e/t.length:0,median:r}})()}getLength=()=>this.text.length;getWordCount=()=>this.words.length;getSentenceCount=()=>this.sentences.length;getAvgWordLength(){return this.words.length?this.words.join("").length/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=()=>O.REGEX.number.test(this.text);getUpperCaseRatio(){const t=this.text.match(O.REGEX.letter)||[],e=this.text.match(O.REGEX.ucLetter)?.length||0;return t.length?e/t.length:0}getCharFrequency(){return Object.fromEntries(this.charFrequency)}getUnicodeCodepoints(){const t={};for(const[e,s]of this.charFrequency){const r=e.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase();t[r]=(t[r]||0)+s}return t}getLongWordRatio(t=7){let e=0;for(const s of this.words)s.length>=t&&e++;return this.words.length?e/this.words.length:0}getShortWordRatio(t=3){let e=0;for(const s of this.words)s.length<=t&&e++;return this.words.length?e/this.words.length:0}getSyllablesCount(){return this.computeSyllableStats().total}getMonosyllabicWordCount(){return this.computeSyllableStats().mono}getMinSyllablesWordCount(t){return this.computeSyllableStats().perWord.filter(e=>e>=t).length}getMaxSyllablesWordCount(t){return this.computeSyllableStats().perWord.filter(e=>e<=t).length}getAvgSyllablesPerWord(){return this.computeSyllableStats().avg}getMedianSyllablesPerWord(){return this.computeSyllableStats().median}getHonoresR(){try{return 100*Math.log(this.words.length)/(1-this.getHapaxLegomena().length/(this.wordHistogram.size??1))}catch{return 0}}getReadingTime(t=200){return this.words.length/(t??1)}getReadabilityScore(t="flesch"){const e=this.words.length||1,s=e/(this.sentences.length||1),r=(this.getSyllablesCount()||1)/e;switch(t){case"flesch":return 206.835-1.015*s-84.6*r;case"fleschde":return 180-s-58.5*r;case"kincaid":return.39*s+11.8*r-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,s=this.getAvgSentenceLength(),r=100*this.getLongWordRatio();return[.1935*e+.1672*s+.1297*r-this.getMonosyllabicWordCount()/t*100*.0327-.875,.2007*e+.1682*s+.1373*r-2.779,.2963*e+.1905*s-1.1144,.2744*e+.2656*s-1.693]}}const E=x.getInstance();class j{static cache=new b;metric;a;b;origA=[];origB=[];options;optKey;symmetric;results;static clear=()=>this.cache.clear();static swap=(t,e,s,r)=>s>r?[e,t,r,s]:[t,e,s,r];static clamp=t=>Math.max(0,Math.min(1,t));constructor(t,e,s,r={},n=!1){this.metric=t,this.a=Array.isArray(e)?e:[e],this.b=Array.isArray(s)?s:[s],a.assert(this.a.length>0&&this.b.length>0,"Inputs <a> and <b> must not be empty",{a:this.a,b:this.b}),this.options=r,this.optKey=w.fastFNV1a(JSON.stringify(r,Object.keys(r).sort())).toString(),this.symmetric=n}preCompute(t,e,s,r){return t===e?{res:1}:0==s||0==r||s<2&&r<2?{res:0}:void 0}compute(t,e,s,r,n){throw new i("Method compute() must be overridden in a subclass")}runSingle(t,e){return a.wrap(()=>{let s=String(this.a[t]),r=s,n=String(this.b[e]),i=n,a=r.length,o=i.length,c=this.preCompute(r,i,a,o);return c||(c=E.run(()=>{this.symmetric&&([r,i,a,o]=j.swap(r,i,a,o));const t=j.cache.key(this.metric,[r,i],this.symmetric)+this.optKey;return j.cache.get(t||"")??(()=>{const e=this.compute(r,i,a,o,Math.max(a,o));return t&&j.cache.set(t,e),e})()})),{metric:this.metric,a:this.origA[t]??s,b:this.origB[e]??n,...c}},`Failed to compute metric for inputs at indices a[${t}] and b[${e}]`,{i:t,j:e})}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 s=0;s<this.b.length;s++)t.push(this.runSingle(e,s));this.results=t}async runBatchAsync(){const t=[];for(let e=0;e<this.a.length;e++)for(let s=0;s<this.b.length;s++)t.push(await this.runSingleAsync(e,s));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=()=>this.a.length>1||this.b.length>1;isSingle=()=>!this.isBatch();isPairwise(t=!1){return!(!this.isBatch()||this.a.length!==this.b.length)||!t&&(()=>{throw new n("Mode <pairwise> requires arrays of equal length",{a:this.a,b:this.b})})()}isSymmetrical=()=>this.symmetric;whichMode=t=>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 i(`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 i(`Unsupported async mode <${t}>`)}}getMetricName=()=>this.metric;getResults(){return a.assert(void 0!==this.results,"run() must be called before getResults()"),this.results}}const L=k("metric",j);L.add("cosine",class extends j{constructor(t,e,s={}){super("cosine",t,e,s,!0)}_termFreq(t,e){const s=t.split(e),r=C.acquire("map",s.length);for(const t of s)r.set(t,(r.get(t)||0)+1);return r}compute(t,e){const{delimiter:s=" "}=this.options,r=this._termFreq(t,s),n=this._termFreq(e,s);try{let t=0,e=0,s=0;for(const[s,i]of r)t+=i*(n.get(s)||0),e+=i*i;for(const t of n.values())s+=t*t;return e=Math.sqrt(e),s=Math.sqrt(s),{res:e&&s?j.clamp(t/(e*s)):0,raw:{dotProduct:t,magnitudeA:e,magnitudeB:s}}}finally{C.release("map",r,r.size),C.release("map",n,n.size)}}}),L.add("damerau",class extends j{constructor(t,e,s={}){super("damerau",t,e,s,!0)}compute(t,e,s,r,n){const i=s+1,[a,o,c]=C.acquireMany("int32",[i,i,i]);try{for(let t=0;t<=s;t++)o[t]=t;for(let n=1;n<=r;n++){c[0]=n;const r=e.charCodeAt(n-1);for(let i=1;i<=s;i++){const s=t.charCodeAt(i-1),l=s===r?0:1;let h=Math.min(c[i-1]+1,o[i]+1,o[i-1]+l);i>1&&n>1&&s===e.charCodeAt(n-2)&&r===t.charCodeAt(i-2)&&(h=Math.min(h,a[i-2]+l)),c[i]=h}a.set(o),o.set(c)}const i=o[s];return{res:0===n?1:j.clamp(1-i/n),raw:{dist:i,maxLen:n}}}finally{C.release("int32",a,i),C.release("int32",o,i),C.release("int32",c,i)}}}),L.add("dice",class extends j{constructor(t,e,s={}){super("dice",t,e,s,!0)}_bigrams(t){const e=t.length-1,s=C.acquire("set",e);for(let r=0;r<e;r++)s.add(t.substring(r,r+2));return s}compute(t,e){const s=this._bigrams(t),r=this._bigrams(e),n=s.size,i=r.size;try{let t=0;for(const e of s)r.has(e)&&t++;const e=n+i;return{res:0===e?1:j.clamp(2*t/e),raw:{intersection:t,size:e}}}finally{C.release("set",s,n),C.release("set",r,i)}}}),L.add("hamming",class extends j{constructor(t,e,s={}){super("hamming",t,e,s,!0)}compute(t,e,s,r,i){if(s!==r){if(void 0===this.options.pad)throw new n(`Strings must be of equal length for Hamming Distance, a=${s} and b=${r} given, use option.pad for automatic adjustment`,{a:s,b:r});s<i&&(t=t.padEnd(i,this.options.pad)),r<i&&(e=e.padEnd(i,this.options.pad)),s=r=i}let a=0;for(let r=0;r<s;r++)t[r]!==e[r]&&a++;return{res:0===s?1:j.clamp(1-a/s),raw:{dist:a}}}}),L.add("jaccard",class extends j{constructor(t,e,s={}){super("jaccard",t,e,s,!0)}compute(t,e,s,r){const[n,i]=C.acquireMany("set",[s,r]);try{for(const e of t)n.add(e);for(const t of e)i.add(t);let s=0;for(const t of n)i.has(t)&&s++;const r=n.size+i.size-s;return{res:0===r?1:j.clamp(s/r),raw:{intersection:s,union:r}}}finally{C.release("set",n,s),C.release("set",i,r)}}}),L.add("jaroWinkler",class extends j{constructor(t,e,s={}){super("jaroWinkler",t,e,s,!0)}compute(t,e,s,r){const[n,i]=C.acquireMany("int32",[s,r]);try{for(let t=0;t<s;t++)n[t]=0;for(let t=0;t<r;t++)i[t]=0;const a=Math.max(0,Math.floor(r/2)-1);let o=0;for(let c=0;c<s;c++){const s=Math.max(0,c-a),l=Math.min(c+a+1,r);for(let r=s;r<l;r++)if(!i[r]&&t[c]===e[r]){n[c]=1,i[r]=1,o++;break}}let c=0,l=0,h=0,p=0;if(o>0){let a=0;for(let r=0;r<s;r++)if(n[r]){for(;!i[a];)a++;t[r]!==e[a]&&c++,a++}c/=2,l=(o/s+o/r+(o-c)/o)/3;for(let n=0;n<Math.min(4,s,r)&&t[n]===e[n];n++)h++;p=l+.1*h*(1-l)}return{res:j.clamp(p),raw:{matchWindow:a,matches:o,transpos:c,jaro:l,prefix:h}}}finally{C.release("int32",n,s),C.release("int32",i,r)}}}),L.add("lcs",class extends j{constructor(t,e,s={}){super("lcs",t,e,s,!0)}compute(t,e,s,r,n){const i=s+1,[a,o]=C.acquireMany("int32",[i,i]);try{for(let t=0;t<=s;t++)a[t]=0;for(let n=1;n<=r;n++){o[0]=0;const r=e.charCodeAt(n-1);for(let e=1;e<=s;e++)t.charCodeAt(e-1)===r?o[e]=a[e-1]+1:o[e]=Math.max(a[e],o[e-1]);a.set(o)}const i=a[s];return{res:0===n?1:j.clamp(i/n),raw:{lcs:i,maxLen:n}}}finally{C.release("int32",a,i),C.release("int32",o,i)}}}),L.add("levenshtein",class extends j{constructor(t,e,s={}){super("levenshtein",t,e,s,!0)}compute(t,e,s,r,n){const i=s+1,[a,o]=C.acquireMany("int32",[i,i]);try{for(let t=0;t<=s;t++)a[t]=t;for(let n=1;n<=r;n++){o[0]=n;const r=e.charCodeAt(n-1);for(let e=1;e<=s;e++){const s=t.charCodeAt(e-1)===r?0:1;o[e]=Math.min(o[e-1]+1,a[e]+1,a[e-1]+s)}a.set(o)}const i=a[s];return{res:0===n?1:j.clamp(1-i/n),raw:{dist:i,maxLen:n}}}finally{C.release("int32",a,i),C.release("int32",o,i)}}}),L.add("needlemanWunsch",class extends j{constructor(t,e,s={}){super("needlemanWunsch",t,e,s,!0)}compute(t,e,s,r,n){const{match:i=1,mismatch:a=-1,gap:o=-1}=this.options,c=s+1,[l,h]=C.acquireMany("int32",[c,c]);try{l[0]=0;for(let t=1;t<=s;t++)l[t]=l[t-1]+o;for(let n=1;n<=r;n++){h[0]=l[0]+o;const r=e.charCodeAt(n-1);for(let e=1;e<=s;e++){const s=t.charCodeAt(e-1)===r?i:a;h[e]=Math.max(l[e-1]+s,l[e]+o,h[e-1]+o)}l.set(h)}const c=l[s],p=n*i;return{res:0===p?0:j.clamp(c/p),raw:{score:c,denum:p}}}finally{C.release("int32",l,c),C.release("int32",h,c)}}}),L.add("qGram",class extends j{constructor(t,e,s={}){super("qGram",t,e,s,!0)}_qGrams(t,e){const s=Math.max(0,t.length-e+1),r=C.acquire("set",s);for(let n=0;n<s;n++)r.add(t.slice(n,n+e));return r}compute(t,e){const{q:s=2}=this.options,r=this._qGrams(t,s),n=this._qGrams(e,s),i=r.size,a=n.size;try{let t=0;for(const e of r)n.has(e)&&t++;const e=Math.max(i,a);return{res:0===e?1:j.clamp(t/e),raw:{intersection:t,size:e}}}finally{C.release("set",r,i),C.release("set",n,a)}}}),L.add("smithWaterman",class extends j{constructor(t,e,s={}){super("smithWaterman",t,e,s,!0)}compute(t,e,s,r){const{match:n=2,mismatch:i=-1,gap:a=-2}=this.options,o=s+1,[c,l]=C.acquireMany("int32",[o,o]);let h=0;try{for(let t=0;t<=s;t++)c[t]=0;for(let o=1;o<=r;o++){l[0]=0;const r=e.charCodeAt(o-1);for(let e=1;e<=s;e++){const s=t.charCodeAt(e-1)===r?n:i;l[e]=Math.max(0,c[e-1]+s,c[e]+a,l[e-1]+a),l[e]>h&&(h=l[e])}c.set(l)}const o=Math.min(s*n,r*n);return{res:0===o?0:j.clamp(h/o),raw:{score:h,denum:o}}}finally{C.release("int32",c,o),C.release("int32",l,o)}}});const $=x.getInstance();class F{static cache=new b;static default;algo;options;optKey;map;static clear=()=>this.cache.clear();constructor(t,e={}){const s=this.constructor.default??{},n=e.map??s.map;if(!n)throw new r("No mapping specified for phonetic algorithm",{algo:t});const i=q.get(t,n);if(void 0===i)throw new r(`Requested mapping <${n}> is not declared`,{algo:t,mapId:n});this.options=d(d(s,i.options??{}),e),this.optKey=w.fastFNV1a(JSON.stringify(this.options,Object.keys(this.options).sort())).toString(),this.algo=t,this.map=i}applyPattern(t){const{patterns:e=[]}=this.map;if(!e||!e.length)return t;for(const{pattern:s,replace:r,all:n=!1}of e)t=t[n?"replaceAll":"replace"](s,r);return t}applyRules(t,e,s,r){const{ruleset:n=[]}=this.map;if(!n||!n.length)return;const i=s[e-1]||"",a=s[e-2]||"",o=s[e+1]||"",c=s[e+2]||"";for(const l of n)if((!l.char||l.char===t)&&("start"!==l.position||0===e)&&("middle"!==l.position||0!==e&&e!==r-1)&&("end"!==l.position||e===r)&&(!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(s.slice(0,l.leading.length).join("")))&&(!l.trailing||l.trailing.includes(s.slice(-l.trailing.length).join("")))&&(!l.match||l.match.every((t,r)=>s[e+r]===t)))return l.code}encode(t){const{map:e={},ignore:s=[]}=this.map;t=this.applyPattern(t);const r=this.word2Chars(t),n=r.length;let i="",a=null;for(let t=0;t<n;t++){const o=r[t];if(s.includes(o))continue;const c=this.mapChar(o,t,r,n,a,e);if(void 0!==c&&(i+=c,a=c,this.exitEarly(i,t)))break}return this.adjustCode(i,r)}mapChar(t,e,s,r,n,i){const{dedupe:a=!0,fallback:o}=this.options,c=this.applyRules(t,e,s,r)??i[t]??o;return a&&c===n?void 0:c}equalLen(t){const{length:e=-1,pad:s="0"}=this.options;return-1===e?t:(t+s.repeat(e)).slice(0,e)}word2Chars=t=>t.toLowerCase().split("");exitEarly(t,e){const{length:s=-1}=this.options;return s>0&&t.length>=s}adjustCode(t,e){return t}loop(t){return a.wrap(()=>{const e=[];for(const s of t){const t=F.cache.key(this.algo,[s])+this.optKey,r=F.cache.get(t||"")??(()=>{const e=this.encode(s);return t&&F.cache.set(t,e),e})();r&&r.length&&e.push(this.equalLen(r))}return e},"Failed to generate phonetic index",{algo:this.algo,words:t})}async loopAsync(t){return a.wrapAsync(async()=>{const e=[];for(const s of t){const t=F.cache.key(this.algo,[s])+this.optKey,r=await Promise.resolve(F.cache.get(t||"")??(()=>{const e=this.encode(s);return t&&F.cache.set(t,e),e})());r&&r.length&&e.push(this.equalLen(r))}return e},"Failed to generate phonetic index asynchronously",{algo:this.algo,words:t})}getAlgoName=()=>this.algo;getIndex(t){const{delimiter:e=" "}=this.options;return $.run(()=>this.loop(t.split(e).filter(Boolean)).filter(Boolean))}async getIndexAsync(t){const{delimiter:e=" "}=this.options;return(await $.runAsync(async()=>await this.loopAsync(t.split(e).filter(Boolean)))).filter(Boolean)}}const N=k("phonetic",F),q=(()=>{const t=Object.create(null),e=e=>t[e]||=Object.create(null);return Object.freeze({add(t,s,r,n=!1){const i=e(t);a.assert(!(!s||s in i)||n,`Entry <${s}> already exists / use <update=true> to overwrite`,{algo:t,id:s}),i[s]=r},remove(t,s){delete e(t)[s]},has:(t,s)=>s in e(t),get:(t,s)=>e(t)[s],list:t=>Object.keys(e(t))})})();class R extends F{static REGEX={uppercase:/[^A-Z]/gi};static default={map:"en2",delimiter:" ",length:-1,pad:"",dedupe:!1};constructor(t={}){super("caverphone",t)}encode(t){return t=t.replace(R.REGEX.uppercase,"").toLowerCase(),super.encode(t)}mapChar=t=>t;adjustCode=t=>t.toUpperCase()}N.add("caverphone",R),q.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:""}]}),q.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:""}]}),N.add("cologne",class extends F{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","")}}),q.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"}]});class P extends F{static REGEX={adjacent:/([A-BD-Z])\1+/gi,vowel:/[AEIOU]/g};static default={map:"en90",delimiter:" ",length:-1,pad:"",dedupe:!1};constructor(t={}){super("metaphone",t)}encode(t){return t=t.replace(P.REGEX.adjacent,(t,e)=>"C"===e?t:e),super.encode(t)}adjustCode(t){return t.slice(0,1)+t.slice(1).replace(P.REGEX.vowel,"")}}N.add("metaphone",P),q.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:""}]}),N.add("soundex",class extends F{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","")}}),q.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"}}),q.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 I=x.getInstance();class _{static filter={has:y.has,add:y.add,remove:y.remove,pause:y.pause,resume:y.resume,list:y.list,clear:y.clear};static metric={add:L.add,remove:L.remove,has:L.has,list:L.list};static phonetic={add:N.add,remove:N.remove,has:N.has,list:N.list,map:{add:q.add,remove:q.remove,has:q.has,list:q.list}};static profiler=I.services;static clearCache={normalizer:A.clear,filter:y.clearPipeline,metric:j.clear,phonetic:F.clear};static analyze=t=>new O(t);static diff=(t,e,s)=>new f(t,e,s);static create(t){return new _(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(!_.metric.has(e))throw new r("CmpStr <metric> must be set, call .setMetric(), use CmpStr.metric.list() for available metrics",{metric:e});break;case"phonetic":if(!_.phonetic.has(e))throw new r("CmpStr <phonetic> must be set, call .setPhonetic(), use CmpStr.phonetic.list() for available phonetic algorithms",{phonetic:e});break;default:throw new i(`Cmpstr condition <${t}> unknown`)}}assertMany(...t){for(const[e,s]of t)this.assert(e,s)}resolveOptions(t){return d({...this.options??Object.create(null)},t)}normalize(t,e){return A.normalize(t,e??this.options.flags??"")}filter(t,e){return y.apply(e,t)}prepare(t,e){const{flags:s,processors:r}=e??this.options;return s?.length&&(t=this.normalize(t,s)),t=this.filter(t,"input"),r?.phonetic&&(t=this.index(t,r.phonetic)),t}postProcess(t,e){return e?.removeZero&&Array.isArray(t)&&(t=t.filter(t=>t.res>0)),t}index(t,{algo:e,opt:s}){this.assert("phonetic",e);const r=v.phonetic(e,s),n=s?.delimiter??" ";return Array.isArray(t)?t.map(t=>r.getIndex(t).join(n)):r.getIndex(t).join(n)}structured(t,e){return M.create(t,e)}compute(t,e,s,r,n,i){return a.wrap(()=>{const a=this.resolveOptions(s);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=v.metric(a.metric,o,c,a.opt);"prep"!==a.output&&l.setOriginal(t,e),l.run(r);const h=this.postProcess(l.getResults(),a);return this.output(h,n??a.raw)},`Failed to compute metric <${s?.metric??this.options.metric}> for the given inputs`,{a:t,b:e,options:s})}output(t,e){return a.wrap(()=>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},"Failed to resolve output format for the metric result",{result:t,raw:e})}clone=()=>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 d(this.options,t),this}setSerializedOptions(t){return a.wrap(()=>(this.options=JSON.parse(t),this),"Failed to parse serialized options, invalid JSON string",{opt:t})}setOption(t,e){return u(this.options,t,e),this}rmvOption(t){return g(this.options,t),this}setRaw=t=>this.setOption("raw",t);setMetric=t=>this.setOption("metric",t);setFlags=t=>this.setOption("flags",t);rmvFlags=()=>this.rmvOption("flags");setProcessors=t=>this.setOption("processors",t);rmvProcessors=()=>this.rmvOption("processors");getOptions=()=>this.options;getSerializedOptions=()=>JSON.stringify(this.options);getOption=t=>p(this.options,t);test(t,e,s){return this.compute(t,e,s,"single")}compare(t,e,s){return this.compute(t,e,s,"single",!0).res}batchTest(t,e,s){return this.compute(t,e,s,"batch")}batchSorted(t,e,s="desc",r){return this.output(this.compute(t,e,r,"batch",!0).sort((t,e)=>"asc"===s?t.res-e.res:e.res-t.res),r?.raw??this.options.raw)}pairs(t,e,s){return this.compute(t,e,s,"pairwise")}match(t,e,s,r){return this.output(this.compute(t,e,r,"batch",!0).filter(t=>t.res>=s).sort((t,e)=>e.res-t.res),r?.raw??this.options.raw)}closest(t,e,s=1,r){return this.batchSorted(t,e,"desc",r).slice(0,s)}furthest(t,e,s=1,r){return this.batchSorted(t,e,"asc",r).slice(0,s)}search(t,e,s,r){const n=this.resolveOptions({flags:s,processors:r}),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,s){const{algo:r,opt:n}=this.options.processors?.phonetic??{};return this.index(t,{algo:e??r,opt:s??n})}structuredLookup(t,e,s,r){return this.structured(e,s).lookup((t,e,s)=>this.batchTest(t,e,s),t,r)}structuredMatch(t,e,s,r,n){return this.structured(e,s).lookup((t,e,s)=>this.match(t,e,r,s),t,{...n,sort:"desc"})}structuredClosest(t,e,s,r=1,n){return this.structured(e,s).lookup((t,e,s)=>this.closest(t,e,r,s),t,{...n,sort:"desc"})}structuredFurthest(t,e,s,r=1,n){return this.structured(e,s).lookup((t,e,s)=>this.furthest(t,e,r,s),t,{...n,sort:"asc"})}structuredPairs(t,e,s,r,n){return this.structured(t,e).lookupPairs((t,e,s)=>this.pairs(t,e,s),s,r,n)}}class W extends _{static create(t){return new W(t)}constructor(t){super(t)}async normalizeAsync(t,e){return A.normalizeAsync(t,e??this.options.flags??"")}async filterAsync(t,e){return y.applyAsync(e,t)}async prepareAsync(t,e){const{flags:s,processors:r}=e??this.options;return s?.length&&(t=await this.normalizeAsync(t,s)),t=await this.filterAsync(t,"input"),r?.phonetic&&(t=await this.indexAsync(t,r.phonetic)),t}async indexAsync(t,{algo:e,opt:s}){this.assert("phonetic",e);const r=v.phonetic(e,s),n=s?.delimiter??" ";return Array.isArray(t)?Promise.all(t.map(t=>r.getIndexAsync(t).then(t=>t.join(n)))):r.getIndexAsync(t).then(t=>t.join(n))}async computeAsync(t,e,s,r,n,i){return a.wrapAsync(async()=>{const a=this.resolveOptions(s);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=v.metric(a.metric,o,c,a.opt);"prep"!==a.output&&l.setOriginal(t,e),await l.runAsync(r);const h=this.postProcess(l.getResults(),a);return this.output(h,n??a.raw)},`Failed to compute metric <${s?.metric??this.options.metric}> for the given inputs`,{a:t,b:e,opt:s})}async testAsync(t,e,s){return this.computeAsync(t,e,s,"single")}async compareAsync(t,e,s){return(await this.computeAsync(t,e,s,"single",!0)).res}async batchTestAsync(t,e,s){return this.computeAsync(t,e,s,"batch")}async batchSortedAsync(t,e,s="desc",r){const n=await this.computeAsync(t,e,r,"batch",!0);return this.output(n.sort((t,e)=>"asc"===s?t.res-e.res:e.res-t.res),r?.raw??this.options.raw)}async pairsAsync(t,e,s){return this.computeAsync(t,e,s,"pairwise")}async matchAsync(t,e,s,r){const n=await this.computeAsync(t,e,r,"batch",!0);return this.output(n.filter(t=>t.res>=s).sort((t,e)=>e.res-t.res),r?.raw??this.options.raw)}async closestAsync(t,e,s=1,r){return(await this.batchSortedAsync(t,e,"desc",r)).slice(0,s)}async furthestAsync(t,e,s=1,r){return(await this.batchSortedAsync(t,e,"asc",r)).slice(0,s)}async searchAsync(t,e,s,r){const n=this.resolveOptions({flags:s,processors:r}),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,s){const{algo:r,opt:n}=this.options.processors?.phonetic??{};return this.indexAsync(t,{algo:e??r,opt:s??n})}async structuredLookupAsync(t,e,s,r){return await this.structured(e,s).lookupAsync((t,e,s)=>this.batchTestAsync(t,e,s),t,r)}async structuredMatchAsync(t,e,s,r,n){return await this.structured(e,s).lookupAsync((t,e,s)=>this.matchAsync(t,e,r,s),t,{...n,sort:"desc"})}async structuredClosestAsync(t,e,s,r=1,n){return await this.structured(e,s).lookupAsync((t,e,s)=>this.closestAsync(t,e,r,s),t,{...n,sort:"desc"})}async structuredFurthestAsync(t,e,s,r=1,n){return await this.structured(e,s).lookupAsync((t,e,s)=>this.furthestAsync(t,e,r,s),t,{...n,sort:"asc"})}async structuredPairsAsync(t,e,s,r,n){return await this.structured(t,e).lookupPairsAsync((t,e,s)=>this.pairsAsync(t,e,s),s,r,n)}}t.CmpStr=_,t.CmpStrAsync=W,t.CmpStrError=o,t.DeepMerge=m,t.DiffChecker=f,t.Filter=y,t.HashTable=b,t.Hasher=w,t.Metric=j,t.MetricRegistry=L,t.Normalizer=A,t.Phonetic=F,t.PhoneticMappingRegistry=q,t.PhoneticRegistry=N,t.Pool=C,t.Profiler=x,t.StructuredData=M,t.TextAnalyzer=O});
@@ -1,8 +1,9 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
4
  var DeepMerge = require('./utils/DeepMerge.cjs');
5
5
  var DiffChecker = require('./utils/DiffChecker.cjs');
6
+ var Errors = require('./utils/Errors.cjs');
6
7
  var Filter = require('./utils/Filter.cjs');
7
8
  var Normalizer = require('./utils/Normalizer.cjs');
8
9
  var Profiler = require('./utils/Profiler.cjs');
@@ -59,6 +60,7 @@ class CmpStr {
59
60
  static profiler = profiler.services;
60
61
  static clearCache = {
61
62
  normalizer: Normalizer.Normalizer.clear,
63
+ filter: Filter.Filter.clearPipeline,
62
64
  metric: Metric.Metric.clear,
63
65
  phonetic: Phonetic.Phonetic.clear
64
66
  };
@@ -78,20 +80,24 @@ class CmpStr {
78
80
  switch (cond) {
79
81
  case 'metric':
80
82
  if (!CmpStr.metric.has(test))
81
- throw new Error(
83
+ throw new Errors.CmpStrNotFoundError(
82
84
  `CmpStr <metric> must be set, call .setMetric(), ` +
83
- `use CmpStr.metric.list() for available metrics`
85
+ `use CmpStr.metric.list() for available metrics`,
86
+ { metric: test }
84
87
  );
85
88
  break;
86
89
  case 'phonetic':
87
90
  if (!CmpStr.phonetic.has(test))
88
- throw new Error(
91
+ throw new Errors.CmpStrNotFoundError(
89
92
  `CmpStr <phonetic> must be set, call .setPhonetic(), ` +
90
- `use CmpStr.phonetic.list() for available phonetic algorithms`
93
+ `use CmpStr.phonetic.list() for available phonetic algorithms`,
94
+ { phonetic: test }
91
95
  );
92
96
  break;
93
97
  default:
94
- throw new Error(`Cmpstr condition <${cond}> unknown`);
98
+ throw new Errors.CmpStrInternalError(
99
+ `Cmpstr condition <${cond}> unknown`
100
+ );
95
101
  }
96
102
  }
97
103
  assertMany(...cond) {
@@ -133,36 +139,47 @@ class CmpStr {
133
139
  return StructuredData.StructuredData.create(data, key);
134
140
  }
135
141
  compute(a, b, opt, mode, raw, skip) {
136
- const resolved = this.resolveOptions(opt);
137
- this.assert('metric', resolved.metric);
138
- const A = skip ? a : this.prepare(a, resolved);
139
- const B = skip ? b : this.prepare(b, resolved);
140
- if (
141
- resolved.safeEmpty &&
142
- ((Array.isArray(A) && A.length === 0) ||
143
- (Array.isArray(B) && B.length === 0) ||
144
- A === '' ||
145
- B === '')
146
- ) {
147
- return [];
148
- }
149
- const metric = Registry.factory['metric'](
150
- resolved.metric,
151
- A,
152
- B,
153
- resolved.opt
142
+ return Errors.ErrorUtil.wrap(
143
+ () => {
144
+ const resolved = this.resolveOptions(opt);
145
+ this.assert('metric', resolved.metric);
146
+ const A = skip ? a : this.prepare(a, resolved);
147
+ const B = skip ? b : this.prepare(b, resolved);
148
+ if (
149
+ resolved.safeEmpty &&
150
+ ((Array.isArray(A) && A.length === 0) ||
151
+ (Array.isArray(B) && B.length === 0) ||
152
+ A === '' ||
153
+ B === '')
154
+ ) {
155
+ return [];
156
+ }
157
+ const metric = Registry.factory['metric'](
158
+ resolved.metric,
159
+ A,
160
+ B,
161
+ resolved.opt
162
+ );
163
+ if (resolved.output !== 'prep') metric.setOriginal(a, b);
164
+ metric.run(mode);
165
+ const result = this.postProcess(metric.getResults(), resolved);
166
+ return this.output(result, raw ?? resolved.raw);
167
+ },
168
+ `Failed to compute metric <${opt?.metric ?? this.options.metric}> for the given inputs`,
169
+ { a, b, options: opt }
154
170
  );
155
- if (resolved.output !== 'prep') metric.setOriginal(a, b);
156
- metric.run(mode);
157
- const result = this.postProcess(metric.getResults(), resolved);
158
- return this.output(result, raw ?? resolved.raw);
159
171
  }
160
172
  output(result, raw) {
161
- return (raw ?? this.options.raw)
162
- ? result
163
- : Array.isArray(result)
164
- ? result.map((r) => ({ source: r.a, target: r.b, match: r.res }))
165
- : { source: result.a, target: result.b, match: result.res };
173
+ return Errors.ErrorUtil.wrap(
174
+ () =>
175
+ (raw ?? this.options.raw)
176
+ ? result
177
+ : Array.isArray(result)
178
+ ? result.map((r) => ({ source: r.a, target: r.b, match: r.res }))
179
+ : { source: result.a, target: result.b, match: result.res },
180
+ `Failed to resolve output format for the metric result`,
181
+ { result, raw }
182
+ );
166
183
  }
167
184
  clone = () => Object.assign(Object.create(Object.getPrototypeOf(this)), this);
168
185
  reset() {
@@ -178,8 +195,14 @@ class CmpStr {
178
195
  return this;
179
196
  }
180
197
  setSerializedOptions(opt) {
181
- this.options = JSON.parse(opt);
182
- return this;
198
+ return Errors.ErrorUtil.wrap(
199
+ () => {
200
+ this.options = JSON.parse(opt);
201
+ return this;
202
+ },
203
+ `Failed to parse serialized options, invalid JSON string`,
204
+ { opt }
205
+ );
183
206
  }
184
207
  setOption(path, value) {
185
208
  DeepMerge.set(this.options, path, value);
@@ -289,4 +312,3 @@ class CmpStr {
289
312
  }
290
313
 
291
314
  exports.CmpStr = CmpStr;
292
- //# sourceMappingURL=CmpStr.cjs.map
@@ -1,6 +1,7 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
+ var Errors = require('./utils/Errors.cjs');
4
5
  var Filter = require('./utils/Filter.cjs');
5
6
  var Normalizer = require('./utils/Normalizer.cjs');
6
7
  var Registry = require('./utils/Registry.cjs');
@@ -43,29 +44,35 @@ class CmpStrAsync extends CmpStr.CmpStr {
43
44
  : phonetic.getIndexAsync(input).then((r) => r.join(delimiter));
44
45
  }
45
46
  async computeAsync(a, b, opt, mode, raw, skip) {
46
- const resolved = this.resolveOptions(opt);
47
- this.assert('metric', resolved.metric);
48
- const A = skip ? a : await this.prepareAsync(a, resolved);
49
- const B = skip ? b : await this.prepareAsync(b, resolved);
50
- if (
51
- resolved.safeEmpty &&
52
- ((Array.isArray(A) && A.length === 0) ||
53
- (Array.isArray(B) && B.length === 0) ||
54
- A === '' ||
55
- B === '')
56
- ) {
57
- return [];
58
- }
59
- const metric = Registry.factory['metric'](
60
- resolved.metric,
61
- A,
62
- B,
63
- resolved.opt
47
+ return Errors.ErrorUtil.wrapAsync(
48
+ async () => {
49
+ const resolved = this.resolveOptions(opt);
50
+ this.assert('metric', resolved.metric);
51
+ const A = skip ? a : await this.prepareAsync(a, resolved);
52
+ const B = skip ? b : await this.prepareAsync(b, resolved);
53
+ if (
54
+ resolved.safeEmpty &&
55
+ ((Array.isArray(A) && A.length === 0) ||
56
+ (Array.isArray(B) && B.length === 0) ||
57
+ A === '' ||
58
+ B === '')
59
+ ) {
60
+ return [];
61
+ }
62
+ const metric = Registry.factory['metric'](
63
+ resolved.metric,
64
+ A,
65
+ B,
66
+ resolved.opt
67
+ );
68
+ if (resolved.output !== 'prep') metric.setOriginal(a, b);
69
+ await metric.runAsync(mode);
70
+ const result = this.postProcess(metric.getResults(), resolved);
71
+ return this.output(result, raw ?? resolved.raw);
72
+ },
73
+ `Failed to compute metric <${opt?.metric ?? this.options.metric}> for the given inputs`,
74
+ { a, b, opt }
64
75
  );
65
- if (resolved.output !== 'prep') metric.setOriginal(a, b);
66
- await metric.runAsync(mode);
67
- const result = this.postProcess(metric.getResults(), resolved);
68
- return this.output(result, raw ?? resolved.raw);
69
76
  }
70
77
  async testAsync(a, b, opt) {
71
78
  return this.computeAsync(a, b, opt, 'single');
@@ -165,4 +172,3 @@ class CmpStrAsync extends CmpStr.CmpStr {
165
172
  }
166
173
 
167
174
  exports.CmpStrAsync = CmpStrAsync;
168
- //# sourceMappingURL=CmpStrAsync.cjs.map
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
4
  var CmpStr = require('./CmpStr.cjs');
@@ -12,4 +12,3 @@ exports.CmpStrAsync = CmpStrAsync.CmpStrAsync;
12
12
  exports.DiffChecker = DiffChecker.DiffChecker;
13
13
  exports.Normalizer = Normalizer.Normalizer;
14
14
  exports.TextAnalyzer = TextAnalyzer.TextAnalyzer;
15
- //# sourceMappingURL=index.cjs.map
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
4
  var Pool = require('../utils/Pool.cjs');
@@ -43,4 +43,3 @@ class CosineSimilarity extends Metric.Metric {
43
43
  Metric.MetricRegistry.add('cosine', CosineSimilarity);
44
44
 
45
45
  exports.CosineSimilarity = CosineSimilarity;
46
- //# sourceMappingURL=Cosine.cjs.map
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
4
  var Pool = require('../utils/Pool.cjs');
@@ -47,4 +47,3 @@ class DamerauLevenshteinDistance extends Metric.Metric {
47
47
  Metric.MetricRegistry.add('damerau', DamerauLevenshteinDistance);
48
48
 
49
49
  exports.DamerauLevenshteinDistance = DamerauLevenshteinDistance;
50
- //# sourceMappingURL=DamerauLevenshtein.cjs.map
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
4
  var Pool = require('../utils/Pool.cjs');
@@ -36,4 +36,3 @@ class DiceSorensenCoefficient extends Metric.Metric {
36
36
  Metric.MetricRegistry.add('dice', DiceSorensenCoefficient);
37
37
 
38
38
  exports.DiceSorensenCoefficient = DiceSorensenCoefficient;
39
- //# sourceMappingURL=DiceSorensen.cjs.map
@@ -1,7 +1,8 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
4
  var Metric = require('./Metric.cjs');
5
+ var Errors = require('../utils/Errors.cjs');
5
6
 
6
7
  class HammingDistance extends Metric.Metric {
7
8
  constructor(a, b, opt = {}) {
@@ -14,9 +15,10 @@ class HammingDistance extends Metric.Metric {
14
15
  if (n < maxLen) b = b.padEnd(maxLen, this.options.pad);
15
16
  m = n = maxLen;
16
17
  } else
17
- throw new Error(
18
+ throw new Errors.CmpStrUsageError(
18
19
  `Strings must be of equal length for Hamming Distance, a=${m} and b=${n} given, ` +
19
- `use option.pad for automatic adjustment`
20
+ `use option.pad for automatic adjustment`,
21
+ { a: m, b: n }
20
22
  );
21
23
  }
22
24
  let dist = 0;
@@ -30,4 +32,3 @@ class HammingDistance extends Metric.Metric {
30
32
  Metric.MetricRegistry.add('hamming', HammingDistance);
31
33
 
32
34
  exports.HammingDistance = HammingDistance;
33
- //# sourceMappingURL=Hamming.cjs.map
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
4
  var Pool = require('../utils/Pool.cjs');
@@ -29,4 +29,3 @@ class JaccardIndex extends Metric.Metric {
29
29
  Metric.MetricRegistry.add('jaccard', JaccardIndex);
30
30
 
31
31
  exports.JaccardIndex = JaccardIndex;
32
- //# sourceMappingURL=Jaccard.cjs.map
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
4
  var Pool = require('../utils/Pool.cjs');
@@ -61,4 +61,3 @@ class JaroWinklerDistance extends Metric.Metric {
61
61
  Metric.MetricRegistry.add('jaroWinkler', JaroWinklerDistance);
62
62
 
63
63
  exports.JaroWinklerDistance = JaroWinklerDistance;
64
- //# sourceMappingURL=JaroWinkler.cjs.map
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
4
  var Pool = require('../utils/Pool.cjs');
@@ -36,4 +36,3 @@ class LCSMetric extends Metric.Metric {
36
36
  Metric.MetricRegistry.add('lcs', LCSMetric);
37
37
 
38
38
  exports.LCSMetric = LCSMetric;
39
- //# sourceMappingURL=LCS.cjs.map
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.0 build-6929b12-260122 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  'use strict';
3
3
 
4
4
  var Pool = require('../utils/Pool.cjs');
@@ -36,4 +36,3 @@ class LevenshteinDistance extends Metric.Metric {
36
36
  Metric.MetricRegistry.add('levenshtein', LevenshteinDistance);
37
37
 
38
38
  exports.LevenshteinDistance = LevenshteinDistance;
39
- //# sourceMappingURL=Levenshtein.cjs.map