cmpstr 3.2.2 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/CmpStr.esm.js +2149 -1721
  2. package/dist/CmpStr.esm.min.js +2 -2
  3. package/dist/CmpStr.umd.js +2028 -1604
  4. package/dist/CmpStr.umd.min.js +2 -2
  5. package/dist/cjs/CmpStr.cjs +100 -51
  6. package/dist/cjs/CmpStrAsync.cjs +35 -18
  7. package/dist/cjs/index.cjs +1 -1
  8. package/dist/cjs/metric/Cosine.cjs +1 -1
  9. package/dist/cjs/metric/DamerauLevenshtein.cjs +1 -1
  10. package/dist/cjs/metric/DiceSorensen.cjs +1 -1
  11. package/dist/cjs/metric/Hamming.cjs +1 -1
  12. package/dist/cjs/metric/Jaccard.cjs +1 -1
  13. package/dist/cjs/metric/JaroWinkler.cjs +1 -1
  14. package/dist/cjs/metric/LCS.cjs +1 -1
  15. package/dist/cjs/metric/Levenshtein.cjs +1 -1
  16. package/dist/cjs/metric/Metric.cjs +40 -22
  17. package/dist/cjs/metric/NeedlemanWunsch.cjs +1 -1
  18. package/dist/cjs/metric/QGram.cjs +1 -1
  19. package/dist/cjs/metric/SmithWaterman.cjs +1 -1
  20. package/dist/cjs/phonetic/Caverphone.cjs +1 -1
  21. package/dist/cjs/phonetic/Cologne.cjs +1 -1
  22. package/dist/cjs/phonetic/Metaphone.cjs +1 -1
  23. package/dist/cjs/phonetic/Phonetic.cjs +27 -15
  24. package/dist/cjs/phonetic/Soundex.cjs +1 -1
  25. package/dist/cjs/root.cjs +4 -2
  26. package/dist/cjs/utils/DeepMerge.cjs +102 -97
  27. package/dist/cjs/utils/DiffChecker.cjs +1 -1
  28. package/dist/cjs/utils/Errors.cjs +22 -19
  29. package/dist/cjs/utils/Filter.cjs +59 -24
  30. package/dist/cjs/utils/HashTable.cjs +44 -29
  31. package/dist/cjs/utils/Normalizer.cjs +57 -28
  32. package/dist/cjs/utils/OptionsValidator.cjs +211 -0
  33. package/dist/cjs/utils/Pool.cjs +27 -13
  34. package/dist/cjs/utils/Profiler.cjs +41 -27
  35. package/dist/cjs/utils/Registry.cjs +5 -5
  36. package/dist/cjs/utils/StructuredData.cjs +83 -53
  37. package/dist/cjs/utils/TextAnalyzer.cjs +1 -1
  38. package/dist/esm/CmpStr.mjs +101 -52
  39. package/dist/esm/CmpStrAsync.mjs +35 -18
  40. package/dist/esm/index.mjs +1 -1
  41. package/dist/esm/metric/Cosine.mjs +1 -1
  42. package/dist/esm/metric/DamerauLevenshtein.mjs +1 -1
  43. package/dist/esm/metric/DiceSorensen.mjs +1 -1
  44. package/dist/esm/metric/Hamming.mjs +1 -1
  45. package/dist/esm/metric/Jaccard.mjs +1 -1
  46. package/dist/esm/metric/JaroWinkler.mjs +1 -1
  47. package/dist/esm/metric/LCS.mjs +1 -1
  48. package/dist/esm/metric/Levenshtein.mjs +1 -1
  49. package/dist/esm/metric/Metric.mjs +40 -22
  50. package/dist/esm/metric/NeedlemanWunsch.mjs +1 -1
  51. package/dist/esm/metric/QGram.mjs +1 -1
  52. package/dist/esm/metric/SmithWaterman.mjs +1 -1
  53. package/dist/esm/phonetic/Caverphone.mjs +1 -1
  54. package/dist/esm/phonetic/Cologne.mjs +1 -1
  55. package/dist/esm/phonetic/Metaphone.mjs +1 -1
  56. package/dist/esm/phonetic/Phonetic.mjs +30 -15
  57. package/dist/esm/phonetic/Soundex.mjs +1 -1
  58. package/dist/esm/root.mjs +3 -3
  59. package/dist/esm/utils/DeepMerge.mjs +103 -94
  60. package/dist/esm/utils/DiffChecker.mjs +1 -1
  61. package/dist/esm/utils/Errors.mjs +22 -19
  62. package/dist/esm/utils/Filter.mjs +59 -24
  63. package/dist/esm/utils/HashTable.mjs +44 -29
  64. package/dist/esm/utils/Normalizer.mjs +57 -28
  65. package/dist/esm/utils/OptionsValidator.mjs +210 -0
  66. package/dist/esm/utils/Pool.mjs +27 -13
  67. package/dist/esm/utils/Profiler.mjs +41 -27
  68. package/dist/esm/utils/Registry.mjs +5 -5
  69. package/dist/esm/utils/StructuredData.mjs +83 -53
  70. package/dist/esm/utils/TextAnalyzer.mjs +1 -1
  71. package/dist/types/CmpStr.d.ts +22 -15
  72. package/dist/types/CmpStrAsync.d.ts +3 -0
  73. package/dist/types/index.d.ts +3 -3
  74. package/dist/types/metric/Metric.d.ts +9 -9
  75. package/dist/types/phonetic/Phonetic.d.ts +4 -3
  76. package/dist/types/root.d.ts +3 -2
  77. package/dist/types/utils/DeepMerge.d.ts +80 -58
  78. package/dist/types/utils/Errors.d.ts +25 -8
  79. package/dist/types/utils/Filter.d.ts +4 -1
  80. package/dist/types/utils/HashTable.d.ts +12 -11
  81. package/dist/types/utils/Normalizer.d.ts +2 -1
  82. package/dist/types/utils/OptionsValidator.d.ts +193 -0
  83. package/dist/types/utils/Profiler.d.ts +9 -28
  84. package/dist/types/utils/StructuredData.d.ts +3 -0
  85. package/dist/types/utils/Types.d.ts +13 -1
  86. package/package.json +14 -5
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { ErrorUtil } from './utils/Errors.mjs';
3
3
  import { Filter } from './utils/Filter.mjs';
4
4
  import { Normalizer } from './utils/Normalizer.mjs';
@@ -39,10 +39,10 @@ class CmpStrAsync extends CmpStr {
39
39
  : phonetic.getIndexAsync(input).then((r) => r.join(delimiter));
40
40
  }
41
41
  async computeAsync(a, b, opt, mode, raw, skip) {
42
+ const resolved = this.resolveOptions(opt);
43
+ this.assert('metric', resolved.metric);
42
44
  return ErrorUtil.wrapAsync(
43
45
  async () => {
44
- const resolved = this.resolveOptions(opt);
45
- this.assert('metric', resolved.metric);
46
46
  const A = skip ? a : await this.prepareAsync(a, resolved);
47
47
  const B = skip ? b : await this.prepareAsync(b, resolved);
48
48
  if (
@@ -100,23 +100,40 @@ class CmpStrAsync extends CmpStr {
100
100
  const resolved = this.resolveOptions({ flags, processors });
101
101
  const test = await this.prepareAsync(needle, resolved);
102
102
  const hstk = await this.prepareAsync(haystack, resolved);
103
- return haystack.filter((_, i) => hstk[i].includes(test));
103
+ const out = [];
104
+ for (let i = 0; i < hstk.length; i++) {
105
+ if (hstk[i].includes(test)) out.push(haystack[i]);
106
+ }
107
+ return out;
104
108
  }
105
109
  async matrixAsync(input, opt) {
106
- input = await this.prepareAsync(input, this.resolveOptions(opt));
107
- return Promise.all(
108
- input.map(
109
- async (a) =>
110
- await this.computeAsync(
111
- a,
112
- input,
113
- undefined,
114
- 'batch',
115
- true,
116
- true
117
- ).then((r) => r.map((b) => b.res ?? 0))
118
- )
119
- );
110
+ const resolved = this.resolveOptions(opt);
111
+ const arr = await this.prepareAsync(input, resolved);
112
+ const n = arr.length;
113
+ const out = Array.from({ length: n }, () => new Array(n).fill(0));
114
+ for (let i = 0; i < n; i++) {
115
+ await Promise.all(
116
+ Array.from({ length: n - i }, (_, k) => i + k).map(async (j) => {
117
+ if (i === j) {
118
+ out[i][j] = 1;
119
+ } else {
120
+ const score = (
121
+ await this.computeAsync(
122
+ arr[i],
123
+ arr[j],
124
+ resolved,
125
+ 'single',
126
+ true,
127
+ true
128
+ )
129
+ ).res;
130
+ out[i][j] = score;
131
+ out[j][i] = score;
132
+ }
133
+ })
134
+ );
135
+ }
136
+ return out;
120
137
  }
121
138
  async phoneticIndexAsync(input, algo, opt) {
122
139
  const { algo: a, opt: o } = this.options.processors?.phonetic ?? {};
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  export { CmpStr } from './CmpStr.mjs';
3
3
  export { CmpStrAsync } from './CmpStrAsync.mjs';
4
4
  export { DiffChecker } from './utils/DiffChecker.mjs';
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { Pool } from '../utils/Pool.mjs';
3
3
  import { MetricRegistry, Metric } from './Metric.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { Pool } from '../utils/Pool.mjs';
3
3
  import { MetricRegistry, Metric } from './Metric.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { Pool } from '../utils/Pool.mjs';
3
3
  import { MetricRegistry, Metric } from './Metric.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { MetricRegistry, Metric } from './Metric.mjs';
3
3
  import { CmpStrUsageError } from '../utils/Errors.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { Pool } from '../utils/Pool.mjs';
3
3
  import { MetricRegistry, Metric } from './Metric.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { Pool } from '../utils/Pool.mjs';
3
3
  import { MetricRegistry, Metric } from './Metric.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { Pool } from '../utils/Pool.mjs';
3
3
  import { MetricRegistry, Metric } from './Metric.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { Pool } from '../utils/Pool.mjs';
3
3
  import { MetricRegistry, Metric } from './Metric.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import {
3
3
  ErrorUtil,
4
4
  CmpStrInternalError,
@@ -20,9 +20,15 @@ class Metric {
20
20
  optKey;
21
21
  symmetric;
22
22
  results;
23
- static clear = () => this.cache.clear();
24
- static swap = (a, b, m, n) => (m > n ? [b, a, n, m] : [a, b, m, n]);
25
- static clamp = (res) => Math.max(0, Math.min(1, res));
23
+ static clear() {
24
+ this.cache.clear();
25
+ }
26
+ static swap(a, b, m, n) {
27
+ return m > n ? [b, a, n, m] : [a, b, m, n];
28
+ }
29
+ static clamp(res) {
30
+ return Math.max(0, Math.min(1, res));
31
+ }
26
32
  constructor(metric, a, b, opt = {}, symmetric = false) {
27
33
  this.metric = metric;
28
34
  this.a = Array.isArray(a) ? a : [a];
@@ -61,13 +67,13 @@ class Metric {
61
67
  if (!result) {
62
68
  result = profiler.run(() => {
63
69
  if (this.symmetric) [A, B, m, n] = Metric.swap(A, B, m, n);
64
- const key =
65
- Metric.cache.key(this.metric, [A, B], this.symmetric) +
66
- this.optKey;
70
+ let key = Metric.cache.key(this.metric, [A, B], this.symmetric);
71
+ if (key) key += this.optKey;
67
72
  return (
68
73
  Metric.cache.get(key || '') ??
69
74
  (() => {
70
- const res = this.compute(A, B, m, n, Math.max(m, n));
75
+ const maxLen = m > n ? m : n;
76
+ const res = this.compute(A, B, m, n, maxLen);
71
77
  if (key) Metric.cache.set(key, res);
72
78
  return res;
73
79
  })()
@@ -76,8 +82,8 @@ class Metric {
76
82
  }
77
83
  return {
78
84
  metric: this.metric,
79
- a: this.origA[i] ?? a,
80
- b: this.origB[j] ?? b,
85
+ a: this.origA.length > i ? this.origA[i] : a,
86
+ b: this.origB.length > j ? this.origB[j] : b,
81
87
  ...result
82
88
  };
83
89
  },
@@ -96,11 +102,11 @@ class Metric {
96
102
  this.results = results;
97
103
  }
98
104
  async runBatchAsync() {
99
- const results = [];
105
+ const tasks = [];
100
106
  for (let i = 0; i < this.a.length; i++)
101
107
  for (let j = 0; j < this.b.length; j++)
102
- results.push(await this.runSingleAsync(i, j));
103
- this.results = results;
108
+ tasks.push(this.runSingleAsync(i, j));
109
+ this.results = await Promise.all(tasks);
104
110
  }
105
111
  runPairwise() {
106
112
  const results = [];
@@ -108,18 +114,22 @@ class Metric {
108
114
  this.results = results;
109
115
  }
110
116
  async runPairwiseAsync() {
111
- const results = [];
117
+ const tasks = [];
112
118
  for (let i = 0; i < this.a.length; i++)
113
- results.push(await this.runSingleAsync(i, i));
114
- this.results = results;
119
+ tasks.push(this.runSingleAsync(i, i));
120
+ this.results = await Promise.all(tasks);
115
121
  }
116
122
  setOriginal(a, b) {
117
123
  if (a) this.origA = Array.isArray(a) ? a : [a];
118
124
  if (b) this.origB = Array.isArray(b) ? b : [b];
119
125
  return this;
120
126
  }
121
- isBatch = () => this.a.length > 1 || this.b.length > 1;
122
- isSingle = () => !this.isBatch();
127
+ isBatch() {
128
+ return this.a.length > 1 || this.b.length > 1;
129
+ }
130
+ isSingle() {
131
+ return !this.isBatch();
132
+ }
123
133
  isPairwise(safe = false) {
124
134
  return this.isBatch() && this.a.length === this.b.length
125
135
  ? true
@@ -131,9 +141,15 @@ class Metric {
131
141
  );
132
142
  })();
133
143
  }
134
- isSymmetrical = () => this.symmetric;
135
- whichMode = (mode) => mode ?? this.options?.mode ?? 'default';
136
- clear = () => (this.results = undefined);
144
+ isSymmetrical() {
145
+ return this.symmetric;
146
+ }
147
+ whichMode(mode) {
148
+ return mode ?? this.options.mode ?? 'default';
149
+ }
150
+ clear() {
151
+ this.results = undefined;
152
+ }
137
153
  run(mode, clear = true) {
138
154
  if (clear) this.clear();
139
155
  switch (this.whichMode(mode)) {
@@ -176,7 +192,9 @@ class Metric {
176
192
  throw new CmpStrInternalError(`Unsupported async mode <${mode}>`);
177
193
  }
178
194
  }
179
- getMetricName = () => this.metric;
195
+ getMetricName() {
196
+ return this.metric;
197
+ }
180
198
  getResults() {
181
199
  ErrorUtil.assert(
182
200
  this.results !== undefined,
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { Pool } from '../utils/Pool.mjs';
3
3
  import { MetricRegistry, Metric } from './Metric.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { Pool } from '../utils/Pool.mjs';
3
3
  import { MetricRegistry, Metric } from './Metric.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import { Pool } from '../utils/Pool.mjs';
3
3
  import { MetricRegistry, Metric } from './Metric.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import {
3
3
  PhoneticRegistry,
4
4
  PhoneticMappingRegistry,
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import {
3
3
  PhoneticRegistry,
4
4
  PhoneticMappingRegistry,
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import {
3
3
  PhoneticRegistry,
4
4
  PhoneticMappingRegistry,
@@ -1,5 +1,5 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
- import { merge } from '../utils/DeepMerge.mjs';
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
+ import { DeepMerge } from '../utils/DeepMerge.mjs';
3
3
  import { CmpStrNotFoundError, ErrorUtil } from '../utils/Errors.mjs';
4
4
  import { HashTable, Hasher } from '../utils/HashTable.mjs';
5
5
  import { Profiler } from '../utils/Profiler.mjs';
@@ -13,7 +13,10 @@ class Phonetic {
13
13
  options;
14
14
  optKey;
15
15
  map;
16
- static clear = () => this.cache.clear();
16
+ ignoreSet;
17
+ static clear() {
18
+ this.cache.clear();
19
+ }
17
20
  constructor(algo, opt = {}) {
18
21
  const defaults = this.constructor.default ?? {};
19
22
  const mapId = opt.map ?? defaults.map;
@@ -28,34 +31,41 @@ class Phonetic {
28
31
  `Requested mapping <${mapId}> is not declared`,
29
32
  { algo, mapId }
30
33
  );
31
- this.options = merge(merge(defaults, map.options ?? {}), opt);
34
+ this.options = DeepMerge.merge(
35
+ DeepMerge.merge(defaults, map.options ?? {}),
36
+ opt
37
+ );
32
38
  this.optKey = Hasher.fastFNV1a(
33
39
  JSON.stringify(this.options, Object.keys(this.options).sort())
34
40
  ).toString();
35
41
  this.algo = algo;
36
42
  this.map = map;
43
+ this.ignoreSet = new Set(map.ignore ?? []);
37
44
  }
38
45
  applyPattern(word) {
39
46
  const { patterns = [] } = this.map;
40
- if (!patterns || !patterns.length) return word;
47
+ if (!patterns.length) return word;
41
48
  for (const { pattern, replace, all = false } of patterns) {
42
- word = word[all ? 'replaceAll' : 'replace'](pattern, replace);
49
+ word = all
50
+ ? word.replaceAll(pattern, replace)
51
+ : word.replace(pattern, replace);
43
52
  }
44
53
  return word;
45
54
  }
46
55
  applyRules(char, i, chars, charLen) {
47
56
  const { ruleset = [] } = this.map;
48
- if (!ruleset || !ruleset.length) return undefined;
57
+ if (!ruleset.length) return undefined;
49
58
  const prev = chars[i - 1] || '',
50
59
  prev2 = chars[i - 2] || '';
51
60
  const next = chars[i + 1] || '',
52
61
  next2 = chars[i + 2] || '';
62
+ const str = chars.join('');
53
63
  for (const rule of ruleset) {
54
64
  if (rule.char && rule.char !== char) continue;
55
65
  if (rule.position === 'start' && i !== 0) continue;
56
66
  if (rule.position === 'middle' && (i === 0 || i === charLen - 1))
57
67
  continue;
58
- if (rule.position === 'end' && i !== charLen) continue;
68
+ if (rule.position === 'end' && i !== charLen - 1) continue;
59
69
  if (rule.prev && !rule.prev.includes(prev)) continue;
60
70
  if (rule.prevNot && rule.prevNot.includes(prev)) continue;
61
71
  if (rule.prev2 && !rule.prev2.includes(prev2)) continue;
@@ -66,12 +76,12 @@ class Phonetic {
66
76
  if (rule.next2Not && rule.next2Not.includes(next2)) continue;
67
77
  if (
68
78
  rule.leading &&
69
- !rule.leading.includes(chars.slice(0, rule.leading.length).join(''))
79
+ !rule.leading.includes(str.slice(0, rule.leading.length))
70
80
  )
71
81
  continue;
72
82
  if (
73
83
  rule.trailing &&
74
- !rule.trailing.includes(chars.slice(-rule.trailing.length).join(''))
84
+ !rule.trailing.includes(str.slice(-rule.trailing.length))
75
85
  )
76
86
  continue;
77
87
  if (rule.match && !rule.match.every((c, j) => chars[i + j] === c))
@@ -81,7 +91,7 @@ class Phonetic {
81
91
  return undefined;
82
92
  }
83
93
  encode(word) {
84
- const { map = {}, ignore = [] } = this.map;
94
+ const { map = {} } = this.map;
85
95
  word = this.applyPattern(word);
86
96
  const chars = this.word2Chars(word);
87
97
  const charLen = chars.length;
@@ -89,7 +99,7 @@ class Phonetic {
89
99
  lastCode = null;
90
100
  for (let i = 0; i < charLen; i++) {
91
101
  const char = chars[i];
92
- if (ignore.includes(char)) continue;
102
+ if (this.ignoreSet.has(char)) continue;
93
103
  const mapped = this.mapChar(char, i, chars, charLen, lastCode, map);
94
104
  if (mapped === undefined) continue;
95
105
  ((code += mapped), (lastCode = mapped));
@@ -108,7 +118,9 @@ class Phonetic {
108
118
  ? input
109
119
  : (input + pad.repeat(length)).slice(0, length);
110
120
  }
111
- word2Chars = (word) => word.toLowerCase().split('');
121
+ word2Chars(word) {
122
+ return Array.from(word.toLowerCase());
123
+ }
112
124
  exitEarly(code, i) {
113
125
  const { length = -1 } = this.options;
114
126
  return length > 0 && code.length >= length;
@@ -121,7 +133,8 @@ class Phonetic {
121
133
  () => {
122
134
  const index = [];
123
135
  for (const word of words) {
124
- const key = Phonetic.cache.key(this.algo, [word]) + this.optKey;
136
+ let key = Phonetic.cache.key(this.algo, [word]);
137
+ if (key) key += this.optKey;
125
138
  const code =
126
139
  Phonetic.cache.get(key || '') ??
127
140
  (() => {
@@ -159,7 +172,9 @@ class Phonetic {
159
172
  { algo: this.algo, words }
160
173
  );
161
174
  }
162
- getAlgoName = () => this.algo;
175
+ getAlgoName() {
176
+ return this.algo;
177
+ }
163
178
  getIndex(input) {
164
179
  const { delimiter = ' ' } = this.options;
165
180
  return profiler.run(() =>
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  import {
3
3
  PhoneticRegistry,
4
4
  PhoneticMappingRegistry,
package/dist/esm/root.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.3.0 build-3699f85-260318 by Paul Köhler @komed3 / MIT License
2
2
  export { CmpStr } from './CmpStr.mjs';
3
3
  export { CmpStrAsync } from './CmpStrAsync.mjs';
4
4
  export { DiffChecker } from './utils/DiffChecker.mjs';
@@ -25,12 +25,12 @@ export {
25
25
  PhoneticMappingRegistry,
26
26
  PhoneticRegistry
27
27
  } from './phonetic/Phonetic.mjs';
28
- import * as DeepMerge from './utils/DeepMerge.mjs';
29
- export { DeepMerge };
28
+ export { DeepMerge } from './utils/DeepMerge.mjs';
30
29
  import * as Errors from './utils/Errors.mjs';
31
30
  export { Errors as CmpStrError };
32
31
  export { Filter } from './utils/Filter.mjs';
33
32
  export { HashTable, Hasher } from './utils/HashTable.mjs';
33
+ export { OptionsValidator } from './utils/OptionsValidator.mjs';
34
34
  export { Pool } from './utils/Pool.mjs';
35
35
  export { Profiler } from './utils/Profiler.mjs';
36
36
  export { StructuredData } from './utils/StructuredData.mjs';