cmpstr 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/CmpStr.esm.js +6 -1
- package/dist/CmpStr.esm.js.map +1 -1
- package/dist/CmpStr.esm.min.js +2 -2
- package/dist/CmpStr.esm.min.js.map +1 -1
- package/dist/CmpStr.umd.js +6 -1
- package/dist/CmpStr.umd.js.map +1 -1
- package/dist/CmpStr.umd.min.js +2 -2
- package/dist/CmpStr.umd.min.js.map +1 -1
- package/dist/cjs/CmpStr.cjs +2 -1
- package/dist/cjs/CmpStr.cjs.map +1 -1
- package/dist/cjs/CmpStrAsync.cjs +1 -1
- package/dist/cjs/CmpStrAsync.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/metric/Cosine.cjs +1 -1
- package/dist/cjs/metric/Cosine.cjs.map +1 -1
- package/dist/cjs/metric/DamerauLevenshtein.cjs +1 -1
- package/dist/cjs/metric/DamerauLevenshtein.cjs.map +1 -1
- package/dist/cjs/metric/DiceSorensen.cjs +1 -1
- package/dist/cjs/metric/DiceSorensen.cjs.map +1 -1
- package/dist/cjs/metric/Hamming.cjs +1 -1
- package/dist/cjs/metric/Hamming.cjs.map +1 -1
- package/dist/cjs/metric/Jaccard.cjs +1 -1
- package/dist/cjs/metric/Jaccard.cjs.map +1 -1
- package/dist/cjs/metric/JaroWinkler.cjs +1 -1
- package/dist/cjs/metric/JaroWinkler.cjs.map +1 -1
- package/dist/cjs/metric/LCS.cjs +1 -1
- package/dist/cjs/metric/LCS.cjs.map +1 -1
- package/dist/cjs/metric/Levenshtein.cjs +1 -1
- package/dist/cjs/metric/Levenshtein.cjs.map +1 -1
- package/dist/cjs/metric/Metric.cjs +1 -1
- package/dist/cjs/metric/Metric.cjs.map +1 -1
- package/dist/cjs/metric/NeedlemanWunsch.cjs +1 -1
- package/dist/cjs/metric/NeedlemanWunsch.cjs.map +1 -1
- package/dist/cjs/metric/QGram.cjs +1 -1
- package/dist/cjs/metric/QGram.cjs.map +1 -1
- package/dist/cjs/metric/SmithWaterman.cjs +1 -1
- package/dist/cjs/metric/SmithWaterman.cjs.map +1 -1
- package/dist/cjs/phonetic/Caverphone.cjs +1 -1
- package/dist/cjs/phonetic/Caverphone.cjs.map +1 -1
- package/dist/cjs/phonetic/Cologne.cjs +1 -1
- package/dist/cjs/phonetic/Cologne.cjs.map +1 -1
- package/dist/cjs/phonetic/Metaphone.cjs +1 -1
- package/dist/cjs/phonetic/Metaphone.cjs.map +1 -1
- package/dist/cjs/phonetic/Phonetic.cjs +1 -1
- package/dist/cjs/phonetic/Phonetic.cjs.map +1 -1
- package/dist/cjs/phonetic/Soundex.cjs +1 -1
- package/dist/cjs/phonetic/Soundex.cjs.map +1 -1
- package/dist/cjs/root.cjs +1 -1
- package/dist/cjs/utils/DeepMerge.cjs +1 -1
- package/dist/cjs/utils/DeepMerge.cjs.map +1 -1
- package/dist/cjs/utils/DiffChecker.cjs +1 -1
- package/dist/cjs/utils/DiffChecker.cjs.map +1 -1
- package/dist/cjs/utils/Filter.cjs +5 -1
- package/dist/cjs/utils/Filter.cjs.map +1 -1
- package/dist/cjs/utils/HashTable.cjs +1 -1
- package/dist/cjs/utils/HashTable.cjs.map +1 -1
- package/dist/cjs/utils/Normalizer.cjs +1 -1
- package/dist/cjs/utils/Normalizer.cjs.map +1 -1
- package/dist/cjs/utils/Pool.cjs +1 -1
- package/dist/cjs/utils/Pool.cjs.map +1 -1
- package/dist/cjs/utils/Profiler.cjs +1 -1
- package/dist/cjs/utils/Profiler.cjs.map +1 -1
- package/dist/cjs/utils/Registry.cjs +1 -1
- package/dist/cjs/utils/Registry.cjs.map +1 -1
- package/dist/cjs/utils/StructuredData.cjs +1 -1
- package/dist/cjs/utils/StructuredData.cjs.map +1 -1
- package/dist/cjs/utils/TextAnalyzer.cjs +1 -1
- package/dist/cjs/utils/TextAnalyzer.cjs.map +1 -1
- package/dist/esm/CmpStr.mjs +2 -1
- package/dist/esm/CmpStr.mjs.map +1 -1
- package/dist/esm/CmpStrAsync.mjs +1 -1
- package/dist/esm/CmpStrAsync.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/metric/Cosine.mjs +1 -1
- package/dist/esm/metric/Cosine.mjs.map +1 -1
- package/dist/esm/metric/DamerauLevenshtein.mjs +1 -1
- package/dist/esm/metric/DamerauLevenshtein.mjs.map +1 -1
- package/dist/esm/metric/DiceSorensen.mjs +1 -1
- package/dist/esm/metric/DiceSorensen.mjs.map +1 -1
- package/dist/esm/metric/Hamming.mjs +1 -1
- package/dist/esm/metric/Hamming.mjs.map +1 -1
- package/dist/esm/metric/Jaccard.mjs +1 -1
- package/dist/esm/metric/Jaccard.mjs.map +1 -1
- package/dist/esm/metric/JaroWinkler.mjs +1 -1
- package/dist/esm/metric/JaroWinkler.mjs.map +1 -1
- package/dist/esm/metric/LCS.mjs +1 -1
- package/dist/esm/metric/LCS.mjs.map +1 -1
- package/dist/esm/metric/Levenshtein.mjs +1 -1
- package/dist/esm/metric/Levenshtein.mjs.map +1 -1
- package/dist/esm/metric/Metric.mjs +1 -1
- package/dist/esm/metric/Metric.mjs.map +1 -1
- package/dist/esm/metric/NeedlemanWunsch.mjs +1 -1
- package/dist/esm/metric/NeedlemanWunsch.mjs.map +1 -1
- package/dist/esm/metric/QGram.mjs +1 -1
- package/dist/esm/metric/QGram.mjs.map +1 -1
- package/dist/esm/metric/SmithWaterman.mjs +1 -1
- package/dist/esm/metric/SmithWaterman.mjs.map +1 -1
- package/dist/esm/phonetic/Caverphone.mjs +1 -1
- package/dist/esm/phonetic/Caverphone.mjs.map +1 -1
- package/dist/esm/phonetic/Cologne.mjs +1 -1
- package/dist/esm/phonetic/Cologne.mjs.map +1 -1
- package/dist/esm/phonetic/Metaphone.mjs +1 -1
- package/dist/esm/phonetic/Metaphone.mjs.map +1 -1
- package/dist/esm/phonetic/Phonetic.mjs +1 -1
- package/dist/esm/phonetic/Phonetic.mjs.map +1 -1
- package/dist/esm/phonetic/Soundex.mjs +1 -1
- package/dist/esm/phonetic/Soundex.mjs.map +1 -1
- package/dist/esm/root.mjs +1 -1
- package/dist/esm/utils/DeepMerge.mjs +1 -1
- package/dist/esm/utils/DeepMerge.mjs.map +1 -1
- package/dist/esm/utils/DiffChecker.mjs +1 -1
- package/dist/esm/utils/DiffChecker.mjs.map +1 -1
- package/dist/esm/utils/Filter.mjs +5 -1
- package/dist/esm/utils/Filter.mjs.map +1 -1
- package/dist/esm/utils/HashTable.mjs +1 -1
- package/dist/esm/utils/HashTable.mjs.map +1 -1
- package/dist/esm/utils/Normalizer.mjs +1 -1
- package/dist/esm/utils/Normalizer.mjs.map +1 -1
- package/dist/esm/utils/Pool.mjs +1 -1
- package/dist/esm/utils/Pool.mjs.map +1 -1
- package/dist/esm/utils/Profiler.mjs +1 -1
- package/dist/esm/utils/Profiler.mjs.map +1 -1
- package/dist/esm/utils/Registry.mjs +1 -1
- package/dist/esm/utils/Registry.mjs.map +1 -1
- package/dist/esm/utils/StructuredData.mjs +1 -1
- package/dist/esm/utils/StructuredData.mjs.map +1 -1
- package/dist/esm/utils/TextAnalyzer.mjs +1 -1
- package/dist/esm/utils/TextAnalyzer.mjs.map +1 -1
- package/dist/types/CmpStr.d.ts +7 -5
- package/dist/types/CmpStrAsync.d.ts +5 -4
- package/dist/types/index.d.ts +2 -2
- package/dist/types/metric/Cosine.d.ts +2 -1
- package/dist/types/metric/DamerauLevenshtein.d.ts +2 -1
- package/dist/types/metric/DiceSorensen.d.ts +2 -1
- package/dist/types/metric/Hamming.d.ts +2 -1
- package/dist/types/metric/Jaccard.d.ts +2 -1
- package/dist/types/metric/JaroWinkler.d.ts +2 -1
- package/dist/types/metric/LCS.d.ts +2 -1
- package/dist/types/metric/Levenshtein.d.ts +2 -1
- package/dist/types/metric/Metric.d.ts +1 -0
- package/dist/types/metric/NeedlemanWunsch.d.ts +2 -1
- package/dist/types/metric/QGram.d.ts +2 -1
- package/dist/types/metric/SmithWaterman.d.ts +2 -1
- package/dist/types/metric/index.d.ts +1 -0
- package/dist/types/phonetic/Caverphone.d.ts +2 -1
- package/dist/types/phonetic/Cologne.d.ts +2 -1
- package/dist/types/phonetic/Metaphone.d.ts +2 -1
- package/dist/types/phonetic/Phonetic.d.ts +1 -0
- package/dist/types/phonetic/Soundex.d.ts +2 -1
- package/dist/types/phonetic/index.d.ts +1 -0
- package/dist/types/root.d.ts +1 -1
- package/dist/types/utils/DeepMerge.d.ts +2 -1
- package/dist/types/utils/DiffChecker.d.ts +2 -1
- package/dist/types/utils/Filter.d.ts +29 -22
- package/dist/types/utils/HashTable.d.ts +2 -1
- package/dist/types/utils/Normalizer.d.ts +2 -1
- package/dist/types/utils/Pool.d.ts +2 -1
- package/dist/types/utils/Profiler.d.ts +3 -2
- package/dist/types/utils/Registry.d.ts +2 -1
- package/dist/types/utils/StructuredData.d.ts +2 -1
- package/dist/types/utils/TextAnalyzer.d.ts +2 -1
- package/dist/types/utils/Types.d.ts +8 -2
- package/package.json +8 -5
package/dist/CmpStr.esm.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CmpStr v3.2.
|
|
2
|
+
* CmpStr v3.2.1 build-3439ccb-260130
|
|
3
3
|
* This is a lightweight, fast and well performing library for calculating string similarity.
|
|
4
4
|
* (c) 2023-2026 Paul Köhler @komed3 / MIT License
|
|
5
5
|
* Visit https://github.com/komed3/cmpstr and https://npmjs.org/package/cmpstr
|
|
6
6
|
*/
|
|
7
|
-
const t=/\[(\d+)]/g,e=new Map;function r(r){let s=e.get(r);if(s)return s;const n=r.replace(t,".$1").split(".").map(t=>{const e=Number(t);return Number.isInteger(e)&&String(e)===t?e:t});return e.set(r,n),n}function s(t,e,s){let n=t;for(const t of r(e)){if(null==n||!(t in n))return s;n=n[t]}return n}function n(t,e,s){if(""===e)return s;const n=r(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]]=s,i}function i(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]=i(null===e||"object"!=typeof e||Array.isArray(e)?Object.create(null):e,n,r)}}),s}function a(t,e,s=!1){const n=r(e),i=(t,e=0)=>{const r=n[e];if(!t||"object"!=typeof t)return!1;if(e===n.length-1)return delete t[r];if(!i(t[r],e+1))return!1;if(!s){const e=t[r];"object"==typeof e&&(Array.isArray(e)&&e.every(t=>null==t)||!Array.isArray(e)&&0===Object.keys(e).length)&&delete t[r]}return!0};return i(t),t}var o=Object.freeze({__proto__:null,get:s,has:function(t,e){let s=t;for(const t of r(e)){if(null==s||!(t in s))return!1;s=s[t]}return!0},merge:i,rmv:a,set:n});class c{a;b;options;entries=[];grouped=[];diffRun=!1;constructor(t,e,r={}){this.a=t,this.b=e,this.options={mode:"word",caseInsensitive:!1,contextLines:1,groupedLines:!0,expandLines:!1,showChangeMagnitude:!0,maxMagnitudeSymbols:5,lineBreak:"\n",...r},this.computeDiff()}text2lines(){const t=this.a.trim().split(/\r?\n/),e=this.b.trim().split(/\r?\n/);return{linesA:t,linesB:e,maxLen:Math.max(t.length,e.length)}}tokenize(t){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}[0m`:e,u=e=>t?`[37;41m${e}[31;49m`:`-[${e}]`,d=e=>t?`[37;42m${e}[32;49m`:`+[${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 l{static filters=new Map;static pipeline=new Map;static getPipeline(t){const e=l.pipeline.get(t);if(e)return e;const r=l.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 l.pipeline.set(t,n),n}static has(t,e){return!!l.filters.get(t)?.has(e)}static add(t,e,r,s={}){const{priority:n=10,active:i=!0,overrideable:a=!0}=s,o=l.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}),l.filters.set(t,o),l.pipeline.delete(t),0))}static remove(t,e){l.pipeline.delete(t);const r=l.filters.get(t);return!!r&&r.delete(e)}static pause(t,e){l.pipeline.delete(t);const r=l.filters.get(t)?.get(e);return!(!r||(r.active=!1,0))}static resume(t,e){l.pipeline.delete(t);const r=l.filters.get(t)?.get(e);return!(!r||(r.active=!0,0))}static list(t,e=!1){const r=l.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=l.getPipeline(t);return Array.isArray(e)?e.map(r):r(e)}static async applyAsync(t,e){const r=l.getPipeline(t);return Array.isArray(e)?Promise.all(e.map(r)):Promise.resolve(r(e))}static clear(t){t?l.filters.delete(t):l.filters.clear()}}class h{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 p{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>p.MAX_LEN)return!1;const s=e.map(t=>h.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>=p.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 u{static pipeline=new Map;static cache=new p;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(u.pipeline.has(t))return u.pipeline.get(t);const{REGEX:e}=u,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 u.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=>u.normalize(t,e));const r=u.cache.key(e,[t]);if(r&&u.cache.has(r))return u.cache.get(r);const s=u.getPipeline(e)(t);return r&&u.cache.set(r,s),s}static async normalizeAsync(t,e){return await(Array.isArray(t)?Promise.all(t.map(t=>u.normalize(t,e))):Promise.resolve(u.normalize(t,e)))}static clear(){u.pipeline.clear(),u.cache.clear()}}class d{active;static ENV;static instance;nowFn;memFn;store=new Set;totalTime=0;totalMem=0;static detectEnv(){"undefined"!=typeof process?d.ENV="nodejs":"undefined"!=typeof performance?d.ENV="browser":d.ENV="unknown"}static getInstance(t){return d.ENV||d.detectEnv(),d.instance||=new d(t)}constructor(t=!1){switch(this.active=t,d.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 g=Object.create(null),m=Object.create(null);function f(t,e){if(t in g||t in m)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 g[t]=s,m[t]=(e,...r)=>function(t,e,...r){e=function(t,e){if(!(t in g))throw new ReferenceError(`Registry <${t}> does not exist`);return"string"==typeof e?g[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 y{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 w{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 y(64),"number[]":new y(16),"string[]":new y(2),set:new y(8),map:new y(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 b{data;key;static create(t,e){return new b(t,e)}constructor(t,e){this.data=t,this.key=e}extractFrom(t,e){const r=w.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{w.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{w.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{w.release("string[]",n,n.length),w.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{w.release("string[]",n,n.length),w.release("string[]",i,i.length)}}}class A{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=A.REGEX.word.exec(e));)this.words.push(t[0]);this.sentences=this.text.split(A.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(A.REGEX.nonWord,"");if(this.syllableCache.has(e))return this.syllableCache.get(e);const r=e.match(A.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=()=>A.REGEX.number.test(this.text);getUpperCaseRatio(){const t=this.text.match(A.REGEX.letter)||[],e=this.text.match(A.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 x=d.getInstance();class S{static cache=new p;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=h.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=x.run(()=>{this.symmetric&&([s,i,a,o]=S.swap(s,i,a,o));const t=S.cache.key(this.metric,[s,i],this.symmetric)+this.optKey;return S.cache.get(t||"")??(()=>{const e=this.compute(s,i,a,o,Math.max(a,o));return t&&S.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 v=f("metric",S);v.add("cosine",class extends S{constructor(t,e,r={}){super("cosine",t,e,r,!0)}_termFreq(t,e){const r=t.split(e),s=w.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?S.clamp(t/(e*r)):0,raw:{dotProduct:t,magnitudeA:e,magnitudeB:r}}}finally{w.release("map",s,s.size),w.release("map",n,n.size)}}}),v.add("damerau",class extends S{constructor(t,e,r={}){super("damerau",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o,c]=w.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:S.clamp(1-i/n),raw:{dist:i,maxLen:n}}}finally{w.release("int32",a,i),w.release("int32",o,i),w.release("int32",c,i)}}}),v.add("dice",class extends S{constructor(t,e,r={}){super("dice",t,e,r,!0)}_bigrams(t){const e=t.length-1,r=w.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:S.clamp(2*t/e),raw:{intersection:t,size:e}}}finally{w.release("set",r,n),w.release("set",s,i)}}}),v.add("hamming",class extends S{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:S.clamp(1-i/r),raw:{dist:i}}}}),v.add("jaccard",class extends S{constructor(t,e,r={}){super("jaccard",t,e,r,!0)}compute(t,e,r,s){const[n,i]=w.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:S.clamp(r/s),raw:{intersection:r,union:s}}}finally{w.release("set",n,r),w.release("set",i,s)}}}),v.add("jaroWinkler",class extends S{constructor(t,e,r={}){super("jaroWinkler",t,e,r,!0)}compute(t,e,r,s){const[n,i]=w.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:S.clamp(p),raw:{matchWindow:a,matches:o,transpos:c,jaro:l,prefix:h}}}finally{w.release("int32",n,r),w.release("int32",i,s)}}}),v.add("lcs",class extends S{constructor(t,e,r={}){super("lcs",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o]=w.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:S.clamp(i/n),raw:{lcs:i,maxLen:n}}}finally{w.release("int32",a,i),w.release("int32",o,i)}}}),v.add("levenshtein",class extends S{constructor(t,e,r={}){super("levenshtein",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o]=w.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:S.clamp(1-i/n),raw:{dist:i,maxLen:n}}}finally{w.release("int32",a,i),w.release("int32",o,i)}}}),v.add("needlemanWunsch",class extends S{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]=w.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:S.clamp(c/p),raw:{score:c,denum:p}}}finally{w.release("int32",l,c),w.release("int32",h,c)}}}),v.add("qGram",class extends S{constructor(t,e,r={}){super("qGram",t,e,r,!0)}_qGrams(t,e){const r=Math.max(0,t.length-e+1),s=w.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:S.clamp(t/e),raw:{intersection:t,size:e}}}finally{w.release("set",s,i),w.release("set",n,a)}}}),v.add("smithWaterman",class extends S{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]=w.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:S.clamp(h/o),raw:{score:h,denum:o}}}finally{w.release("int32",c,o),w.release("int32",l,o)}}});const z=d.getInstance();class k{static cache=new p;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=C.get(t,s);if(void 0===n)throw new Error(`Requested mapping <${s}> is not declared`);this.options=i(i(r,n.options??{}),e),this.optKey=h.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=k.cache.key(this.algo,[r])+this.optKey,s=k.cache.get(t||"")??(()=>{const e=this.encode(r);return t&&k.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=k.cache.key(this.algo,[r])+this.optKey,s=await Promise.resolve(k.cache.get(t||"")??(()=>{const e=this.encode(r);return t&&k.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 z.run(()=>this.loop(t.split(e).filter(Boolean)).filter(Boolean))}async getIndexAsync(t){const{delimiter:e=" "}=this.options;return(await z.runAsync(async()=>await this.loopAsync(t.split(e).filter(Boolean)))).filter(Boolean)}}const M=f("phonetic",k),C=(()=>{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 E extends k{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(E.REGEX.uppercase,"").toLowerCase(),super.encode(t)}mapChar=t=>t;adjustCode=t=>t.toUpperCase()}M.add("caverphone",E),C.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:""}]}),C.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:""}]}),M.add("cologne",class extends k{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","")}}),C.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 O extends k{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(O.REGEX.adjacent,(t,e)=>"C"===e?t:e),super.encode(t)}adjustCode(t){return t.slice(0,1)+t.slice(1).replace(O.REGEX.vowel,"")}}M.add("metaphone",O),C.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:""}]}),M.add("soundex",class extends k{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","")}}),C.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"}}),C.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 j=d.getInstance();class L{static filter={has:l.has,add:l.add,remove:l.remove,pause:l.pause,resume:l.resume,list:l.list,clear:l.clear};static metric={add:v.add,remove:v.remove,has:v.has,list:v.list};static phonetic={add:M.add,remove:M.remove,has:M.has,list:M.list,map:{add:C.add,remove:C.remove,has:C.has,list:C.list}};static profiler=j.services;static clearCache={normalizer:u.clear,metric:S.clear,phonetic:k.clear};static analyze=t=>new A(t);static diff=(t,e,r)=>new c(t,e,r);static create(t){return new L(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(!L.metric.has(e))throw new Error("CmpStr <metric> must be set, call .setMetric(), use CmpStr.metric.list() for available metrics");break;case"phonetic":if(!L.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 i({...this.options??Object.create(null)},t)}normalize(t,e){return u.normalize(t,e??this.options.flags??"")}filter(t,e){return l.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=m.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 b.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=m.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 i(this.options,t),this}setSerializedOptions(t){return this.options=JSON.parse(t),this}setOption(t,e){return n(this.options,t,e),this}rmvOption(t){return a(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=>s(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 N extends L{static create(t){return new N(t)}constructor(t){super(t)}async normalizeAsync(t,e){return u.normalizeAsync(t,e??this.options.flags??"")}async filterAsync(t,e){return l.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=m.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=m.metric(a.metric,o,c,a.opt);"prep"!==a.output&&l.setOriginal(t,e),await l.runAsync(s);const h=this.postProcess(l.getResults(),a);return this.output(h,n??a.raw)}async testAsync(t,e,r){return this.computeAsync(t,e,r,"single")}async compareAsync(t,e,r){return(await this.computeAsync(t,e,r,"single",!0)).res}async batchTestAsync(t,e,r){return this.computeAsync(t,e,r,"batch")}async batchSortedAsync(t,e,r="desc",s){const n=await this.computeAsync(t,e,s,"batch",!0);return this.output(n.sort((t,e)=>"asc"===r?t.res-e.res:e.res-t.res),s?.raw??this.options.raw)}async pairsAsync(t,e,r){return this.computeAsync(t,e,r,"pairwise")}async matchAsync(t,e,r,s){const n=await this.computeAsync(t,e,s,"batch",!0);return this.output(n.filter(t=>t.res>=r).sort((t,e)=>e.res-t.res),s?.raw??this.options.raw)}async closestAsync(t,e,r=1,s){return(await this.batchSortedAsync(t,e,"desc",s)).slice(0,r)}async furthestAsync(t,e,r=1,s){return(await this.batchSortedAsync(t,e,"asc",s)).slice(0,r)}async searchAsync(t,e,r,s){const n=this.resolveOptions({flags:r,processors:s}),i=await this.prepareAsync(t,n),a=await this.prepareAsync(e,n);return e.filter((t,e)=>a[e].includes(i))}async matrixAsync(t,e){return t=await this.prepareAsync(t,this.resolveOptions(e)),Promise.all(t.map(async e=>await this.computeAsync(e,t,void 0,"batch",!0,!0).then(t=>t.map(t=>t.res??0))))}async phoneticIndexAsync(t,e,r){const{algo:s,opt:n}=this.options.processors?.phonetic??{};return this.indexAsync(t,{algo:e??s,opt:r??n})}async structuredLookupAsync(t,e,r,s){return await this.structured(e,r).lookupAsync((t,e,r)=>this.batchTestAsync(t,e,r),t,s)}async structuredMatchAsync(t,e,r,s,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.matchAsync(t,e,s,r),t,{...n,sort:"desc"})}async structuredClosestAsync(t,e,r,s=1,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.closestAsync(t,e,s,r),t,{...n,sort:"desc"})}async structuredFurthestAsync(t,e,r,s=1,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.furthestAsync(t,e,s,r),t,{...n,sort:"asc"})}async structuredPairsAsync(t,e,r,s,n){return await this.structured(t,e).lookupPairsAsync((t,e,r)=>this.pairsAsync(t,e,r),r,s,n)}}export{L as CmpStr,N as CmpStrAsync,o as DeepMerge,c as DiffChecker,l as Filter,p as HashTable,h as Hasher,S as Metric,v as MetricRegistry,u as Normalizer,k as Phonetic,C as PhoneticMappingRegistry,M as PhoneticRegistry,w as Pool,d as Profiler,b as StructuredData,A as TextAnalyzer};
|
|
7
|
+
const t=/\[(\d+)]/g,e=new Map;function r(r){let s=e.get(r);if(s)return s;const n=r.replace(t,".$1").split(".").map(t=>{const e=Number(t);return Number.isInteger(e)&&String(e)===t?e:t});return e.set(r,n),n}function s(t,e,s){let n=t;for(const t of r(e)){if(null==n||!(t in n))return s;n=n[t]}return n}function n(t,e,s){if(""===e)return s;const n=r(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]]=s,i}function i(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]=i(null===e||"object"!=typeof e||Array.isArray(e)?Object.create(null):e,n,r)}}),s}function a(t,e,s=!1){const n=r(e),i=(t,e=0)=>{const r=n[e];if(!t||"object"!=typeof t)return!1;if(e===n.length-1)return delete t[r];if(!i(t[r],e+1))return!1;if(!s){const e=t[r];"object"==typeof e&&(Array.isArray(e)&&e.every(t=>null==t)||!Array.isArray(e)&&0===Object.keys(e).length)&&delete t[r]}return!0};return i(t),t}var o=Object.freeze({__proto__:null,get:s,has:function(t,e){let s=t;for(const t of r(e)){if(null==s||!(t in s))return!1;s=s[t]}return!0},merge:i,rmv:a,set:n});class c{a;b;options;entries=[];grouped=[];diffRun=!1;constructor(t,e,r={}){this.a=t,this.b=e,this.options={mode:"word",caseInsensitive:!1,contextLines:1,groupedLines:!0,expandLines:!1,showChangeMagnitude:!0,maxMagnitudeSymbols:5,lineBreak:"\n",...r},this.computeDiff()}text2lines(){const t=this.a.trim().split(/\r?\n/),e=this.b.trim().split(/\r?\n/);return{linesA:t,linesB:e,maxLen:Math.max(t.length,e.length)}}tokenize(t){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}[0m`:e,u=e=>t?`[37;41m${e}[31;49m`:`-[${e}]`,d=e=>t?`[37;42m${e}[32;49m`:`+[${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 l{static filters=new Map;static pipeline=new Map;static getPipeline(t){const e=l.pipeline.get(t);if(e)return e;const r=l.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 l.pipeline.set(t,n),n}static has(t,e){return!!l.filters.get(t)?.has(e)}static add(t,e,r,s={}){const{priority:n=10,active:i=!0,overrideable:a=!0}=s,o=l.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}),l.filters.set(t,o),l.pipeline.delete(t),0))}static remove(t,e){l.pipeline.delete(t);const r=l.filters.get(t);return!!r&&r.delete(e)}static pause(t,e){l.pipeline.delete(t);const r=l.filters.get(t)?.get(e);return!(!r||(r.active=!1,0))}static resume(t,e){l.pipeline.delete(t);const r=l.filters.get(t)?.get(e);return!(!r||(r.active=!0,0))}static list(t,e=!1){const r=l.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=l.getPipeline(t);return Array.isArray(e)?e.map(r):r(e)}static async applyAsync(t,e){const r=l.getPipeline(t);return Array.isArray(e)?Promise.all(e.map(r)):Promise.resolve(r(e))}static clear(t){l.pipeline.clear(),t?l.filters.delete(t):l.filters.clear()}static clearPipeline(){l.pipeline.clear()}}class h{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 p{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>p.MAX_LEN)return!1;const s=e.map(t=>h.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>=p.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 u{static pipeline=new Map;static cache=new p;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(u.pipeline.has(t))return u.pipeline.get(t);const{REGEX:e}=u,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 u.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=>u.normalize(t,e));const r=u.cache.key(e,[t]);if(r&&u.cache.has(r))return u.cache.get(r);const s=u.getPipeline(e)(t);return r&&u.cache.set(r,s),s}static async normalizeAsync(t,e){return await(Array.isArray(t)?Promise.all(t.map(t=>u.normalize(t,e))):Promise.resolve(u.normalize(t,e)))}static clear(){u.pipeline.clear(),u.cache.clear()}}class d{active;static ENV;static instance;nowFn;memFn;store=new Set;totalTime=0;totalMem=0;static detectEnv(){"undefined"!=typeof process?d.ENV="nodejs":"undefined"!=typeof performance?d.ENV="browser":d.ENV="unknown"}static getInstance(t){return d.ENV||d.detectEnv(),d.instance||=new d(t)}constructor(t=!1){switch(this.active=t,d.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 g=Object.create(null),m=Object.create(null);function f(t,e){if(t in g||t in m)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 g[t]=s,m[t]=(e,...r)=>function(t,e,...r){e=function(t,e){if(!(t in g))throw new ReferenceError(`Registry <${t}> does not exist`);return"string"==typeof e?g[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 y{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 w{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 y(64),"number[]":new y(16),"string[]":new y(2),set:new y(8),map:new y(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 b{data;key;static create(t,e){return new b(t,e)}constructor(t,e){this.data=t,this.key=e}extractFrom(t,e){const r=w.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{w.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{w.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{w.release("string[]",n,n.length),w.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{w.release("string[]",n,n.length),w.release("string[]",i,i.length)}}}class A{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=A.REGEX.word.exec(e));)this.words.push(t[0]);this.sentences=this.text.split(A.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(A.REGEX.nonWord,"");if(this.syllableCache.has(e))return this.syllableCache.get(e);const r=e.match(A.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=()=>A.REGEX.number.test(this.text);getUpperCaseRatio(){const t=this.text.match(A.REGEX.letter)||[],e=this.text.match(A.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 x=d.getInstance();class S{static cache=new p;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=h.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=x.run(()=>{this.symmetric&&([s,i,a,o]=S.swap(s,i,a,o));const t=S.cache.key(this.metric,[s,i],this.symmetric)+this.optKey;return S.cache.get(t||"")??(()=>{const e=this.compute(s,i,a,o,Math.max(a,o));return t&&S.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 v=f("metric",S);v.add("cosine",class extends S{constructor(t,e,r={}){super("cosine",t,e,r,!0)}_termFreq(t,e){const r=t.split(e),s=w.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?S.clamp(t/(e*r)):0,raw:{dotProduct:t,magnitudeA:e,magnitudeB:r}}}finally{w.release("map",s,s.size),w.release("map",n,n.size)}}}),v.add("damerau",class extends S{constructor(t,e,r={}){super("damerau",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o,c]=w.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:S.clamp(1-i/n),raw:{dist:i,maxLen:n}}}finally{w.release("int32",a,i),w.release("int32",o,i),w.release("int32",c,i)}}}),v.add("dice",class extends S{constructor(t,e,r={}){super("dice",t,e,r,!0)}_bigrams(t){const e=t.length-1,r=w.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:S.clamp(2*t/e),raw:{intersection:t,size:e}}}finally{w.release("set",r,n),w.release("set",s,i)}}}),v.add("hamming",class extends S{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:S.clamp(1-i/r),raw:{dist:i}}}}),v.add("jaccard",class extends S{constructor(t,e,r={}){super("jaccard",t,e,r,!0)}compute(t,e,r,s){const[n,i]=w.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:S.clamp(r/s),raw:{intersection:r,union:s}}}finally{w.release("set",n,r),w.release("set",i,s)}}}),v.add("jaroWinkler",class extends S{constructor(t,e,r={}){super("jaroWinkler",t,e,r,!0)}compute(t,e,r,s){const[n,i]=w.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:S.clamp(p),raw:{matchWindow:a,matches:o,transpos:c,jaro:l,prefix:h}}}finally{w.release("int32",n,r),w.release("int32",i,s)}}}),v.add("lcs",class extends S{constructor(t,e,r={}){super("lcs",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o]=w.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:S.clamp(i/n),raw:{lcs:i,maxLen:n}}}finally{w.release("int32",a,i),w.release("int32",o,i)}}}),v.add("levenshtein",class extends S{constructor(t,e,r={}){super("levenshtein",t,e,r,!0)}compute(t,e,r,s,n){const i=r+1,[a,o]=w.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:S.clamp(1-i/n),raw:{dist:i,maxLen:n}}}finally{w.release("int32",a,i),w.release("int32",o,i)}}}),v.add("needlemanWunsch",class extends S{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]=w.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:S.clamp(c/p),raw:{score:c,denum:p}}}finally{w.release("int32",l,c),w.release("int32",h,c)}}}),v.add("qGram",class extends S{constructor(t,e,r={}){super("qGram",t,e,r,!0)}_qGrams(t,e){const r=Math.max(0,t.length-e+1),s=w.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:S.clamp(t/e),raw:{intersection:t,size:e}}}finally{w.release("set",s,i),w.release("set",n,a)}}}),v.add("smithWaterman",class extends S{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]=w.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:S.clamp(h/o),raw:{score:h,denum:o}}}finally{w.release("int32",c,o),w.release("int32",l,o)}}});const z=d.getInstance();class k{static cache=new p;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=C.get(t,s);if(void 0===n)throw new Error(`Requested mapping <${s}> is not declared`);this.options=i(i(r,n.options??{}),e),this.optKey=h.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=k.cache.key(this.algo,[r])+this.optKey,s=k.cache.get(t||"")??(()=>{const e=this.encode(r);return t&&k.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=k.cache.key(this.algo,[r])+this.optKey,s=await Promise.resolve(k.cache.get(t||"")??(()=>{const e=this.encode(r);return t&&k.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 z.run(()=>this.loop(t.split(e).filter(Boolean)).filter(Boolean))}async getIndexAsync(t){const{delimiter:e=" "}=this.options;return(await z.runAsync(async()=>await this.loopAsync(t.split(e).filter(Boolean)))).filter(Boolean)}}const M=f("phonetic",k),C=(()=>{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 E extends k{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(E.REGEX.uppercase,"").toLowerCase(),super.encode(t)}mapChar=t=>t;adjustCode=t=>t.toUpperCase()}M.add("caverphone",E),C.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:""}]}),C.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:""}]}),M.add("cologne",class extends k{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","")}}),C.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 O extends k{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(O.REGEX.adjacent,(t,e)=>"C"===e?t:e),super.encode(t)}adjustCode(t){return t.slice(0,1)+t.slice(1).replace(O.REGEX.vowel,"")}}M.add("metaphone",O),C.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:""}]}),M.add("soundex",class extends k{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","")}}),C.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"}}),C.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 j=d.getInstance();class L{static filter={has:l.has,add:l.add,remove:l.remove,pause:l.pause,resume:l.resume,list:l.list,clear:l.clear};static metric={add:v.add,remove:v.remove,has:v.has,list:v.list};static phonetic={add:M.add,remove:M.remove,has:M.has,list:M.list,map:{add:C.add,remove:C.remove,has:C.has,list:C.list}};static profiler=j.services;static clearCache={normalizer:u.clear,filter:l.clearPipeline,metric:S.clear,phonetic:k.clear};static analyze=t=>new A(t);static diff=(t,e,r)=>new c(t,e,r);static create(t){return new L(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(!L.metric.has(e))throw new Error("CmpStr <metric> must be set, call .setMetric(), use CmpStr.metric.list() for available metrics");break;case"phonetic":if(!L.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 i({...this.options??Object.create(null)},t)}normalize(t,e){return u.normalize(t,e??this.options.flags??"")}filter(t,e){return l.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=m.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 b.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=m.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 i(this.options,t),this}setSerializedOptions(t){return this.options=JSON.parse(t),this}setOption(t,e){return n(this.options,t,e),this}rmvOption(t){return a(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=>s(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 N extends L{static create(t){return new N(t)}constructor(t){super(t)}async normalizeAsync(t,e){return u.normalizeAsync(t,e??this.options.flags??"")}async filterAsync(t,e){return l.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=m.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=m.metric(a.metric,o,c,a.opt);"prep"!==a.output&&l.setOriginal(t,e),await l.runAsync(s);const h=this.postProcess(l.getResults(),a);return this.output(h,n??a.raw)}async testAsync(t,e,r){return this.computeAsync(t,e,r,"single")}async compareAsync(t,e,r){return(await this.computeAsync(t,e,r,"single",!0)).res}async batchTestAsync(t,e,r){return this.computeAsync(t,e,r,"batch")}async batchSortedAsync(t,e,r="desc",s){const n=await this.computeAsync(t,e,s,"batch",!0);return this.output(n.sort((t,e)=>"asc"===r?t.res-e.res:e.res-t.res),s?.raw??this.options.raw)}async pairsAsync(t,e,r){return this.computeAsync(t,e,r,"pairwise")}async matchAsync(t,e,r,s){const n=await this.computeAsync(t,e,s,"batch",!0);return this.output(n.filter(t=>t.res>=r).sort((t,e)=>e.res-t.res),s?.raw??this.options.raw)}async closestAsync(t,e,r=1,s){return(await this.batchSortedAsync(t,e,"desc",s)).slice(0,r)}async furthestAsync(t,e,r=1,s){return(await this.batchSortedAsync(t,e,"asc",s)).slice(0,r)}async searchAsync(t,e,r,s){const n=this.resolveOptions({flags:r,processors:s}),i=await this.prepareAsync(t,n),a=await this.prepareAsync(e,n);return e.filter((t,e)=>a[e].includes(i))}async matrixAsync(t,e){return t=await this.prepareAsync(t,this.resolveOptions(e)),Promise.all(t.map(async e=>await this.computeAsync(e,t,void 0,"batch",!0,!0).then(t=>t.map(t=>t.res??0))))}async phoneticIndexAsync(t,e,r){const{algo:s,opt:n}=this.options.processors?.phonetic??{};return this.indexAsync(t,{algo:e??s,opt:r??n})}async structuredLookupAsync(t,e,r,s){return await this.structured(e,r).lookupAsync((t,e,r)=>this.batchTestAsync(t,e,r),t,s)}async structuredMatchAsync(t,e,r,s,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.matchAsync(t,e,s,r),t,{...n,sort:"desc"})}async structuredClosestAsync(t,e,r,s=1,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.closestAsync(t,e,s,r),t,{...n,sort:"desc"})}async structuredFurthestAsync(t,e,r,s=1,n){return await this.structured(e,r).lookupAsync((t,e,r)=>this.furthestAsync(t,e,s,r),t,{...n,sort:"asc"})}async structuredPairsAsync(t,e,r,s,n){return await this.structured(t,e).lookupPairsAsync((t,e,r)=>this.pairsAsync(t,e,r),r,s,n)}}export{L as CmpStr,N as CmpStrAsync,o as DeepMerge,c as DiffChecker,l as Filter,p as HashTable,h as Hasher,S as Metric,v as MetricRegistry,u as Normalizer,k as Phonetic,C as PhoneticMappingRegistry,M as PhoneticRegistry,w as Pool,d as Profiler,b as StructuredData,A as TextAnalyzer};
|
|
8
8
|
//# sourceMappingURL=CmpStr.esm.min.js.map
|