cmpstr 3.2.1 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +24 -18
  2. package/dist/CmpStr.esm.js +485 -220
  3. package/dist/CmpStr.esm.min.js +2 -3
  4. package/dist/CmpStr.umd.js +484 -220
  5. package/dist/CmpStr.umd.min.js +2 -3
  6. package/dist/cjs/CmpStr.cjs +57 -36
  7. package/dist/cjs/CmpStrAsync.cjs +30 -24
  8. package/dist/cjs/index.cjs +1 -2
  9. package/dist/cjs/metric/Cosine.cjs +1 -2
  10. package/dist/cjs/metric/DamerauLevenshtein.cjs +1 -2
  11. package/dist/cjs/metric/DiceSorensen.cjs +1 -2
  12. package/dist/cjs/metric/Hamming.cjs +5 -4
  13. package/dist/cjs/metric/Jaccard.cjs +1 -2
  14. package/dist/cjs/metric/JaroWinkler.cjs +1 -2
  15. package/dist/cjs/metric/LCS.cjs +1 -2
  16. package/dist/cjs/metric/Levenshtein.cjs +1 -2
  17. package/dist/cjs/metric/Metric.cjs +57 -38
  18. package/dist/cjs/metric/NeedlemanWunsch.cjs +1 -2
  19. package/dist/cjs/metric/QGram.cjs +1 -2
  20. package/dist/cjs/metric/SmithWaterman.cjs +1 -2
  21. package/dist/cjs/phonetic/Caverphone.cjs +1 -2
  22. package/dist/cjs/phonetic/Cologne.cjs +1 -2
  23. package/dist/cjs/phonetic/Metaphone.cjs +1 -2
  24. package/dist/cjs/phonetic/Phonetic.cjs +55 -35
  25. package/dist/cjs/phonetic/Soundex.cjs +1 -2
  26. package/dist/cjs/root.cjs +3 -2
  27. package/dist/cjs/utils/DeepMerge.cjs +10 -5
  28. package/dist/cjs/utils/DiffChecker.cjs +1 -2
  29. package/dist/cjs/utils/Errors.cjs +103 -0
  30. package/dist/cjs/utils/Filter.cjs +52 -27
  31. package/dist/cjs/utils/HashTable.cjs +1 -2
  32. package/dist/cjs/utils/Normalizer.cjs +54 -34
  33. package/dist/cjs/utils/Pool.cjs +42 -18
  34. package/dist/cjs/utils/Profiler.cjs +1 -2
  35. package/dist/cjs/utils/Registry.cjs +46 -22
  36. package/dist/cjs/utils/StructuredData.cjs +13 -5
  37. package/dist/cjs/utils/TextAnalyzer.cjs +1 -2
  38. package/dist/esm/CmpStr.mjs +55 -32
  39. package/dist/esm/CmpStrAsync.mjs +26 -20
  40. package/dist/esm/index.mjs +1 -2
  41. package/dist/esm/metric/Cosine.mjs +1 -2
  42. package/dist/esm/metric/DamerauLevenshtein.mjs +1 -2
  43. package/dist/esm/metric/DiceSorensen.mjs +1 -2
  44. package/dist/esm/metric/Hamming.mjs +5 -4
  45. package/dist/esm/metric/Jaccard.mjs +1 -2
  46. package/dist/esm/metric/JaroWinkler.mjs +1 -2
  47. package/dist/esm/metric/LCS.mjs +1 -2
  48. package/dist/esm/metric/Levenshtein.mjs +1 -2
  49. package/dist/esm/metric/Metric.mjs +59 -38
  50. package/dist/esm/metric/NeedlemanWunsch.mjs +1 -2
  51. package/dist/esm/metric/QGram.mjs +1 -2
  52. package/dist/esm/metric/SmithWaterman.mjs +1 -2
  53. package/dist/esm/phonetic/Caverphone.mjs +1 -2
  54. package/dist/esm/phonetic/Cologne.mjs +1 -2
  55. package/dist/esm/phonetic/Metaphone.mjs +1 -2
  56. package/dist/esm/phonetic/Phonetic.mjs +55 -35
  57. package/dist/esm/phonetic/Soundex.mjs +1 -2
  58. package/dist/esm/root.mjs +3 -2
  59. package/dist/esm/utils/DeepMerge.mjs +10 -5
  60. package/dist/esm/utils/DiffChecker.mjs +1 -2
  61. package/dist/esm/utils/Errors.mjs +103 -0
  62. package/dist/esm/utils/Filter.mjs +52 -27
  63. package/dist/esm/utils/HashTable.mjs +1 -2
  64. package/dist/esm/utils/Normalizer.mjs +54 -34
  65. package/dist/esm/utils/Pool.mjs +38 -18
  66. package/dist/esm/utils/Profiler.mjs +1 -2
  67. package/dist/esm/utils/Registry.mjs +46 -22
  68. package/dist/esm/utils/StructuredData.mjs +13 -5
  69. package/dist/esm/utils/TextAnalyzer.mjs +1 -2
  70. package/dist/types/CmpStr.d.ts +5 -1
  71. package/dist/types/CmpStrAsync.d.ts +1 -0
  72. package/dist/types/index.d.ts +3 -2
  73. package/dist/types/metric/Metric.d.ts +6 -5
  74. package/dist/types/phonetic/Phonetic.d.ts +3 -1
  75. package/dist/types/root.d.ts +2 -1
  76. package/dist/types/utils/DeepMerge.d.ts +1 -1
  77. package/dist/types/utils/Errors.d.ts +137 -0
  78. package/dist/types/utils/Filter.d.ts +4 -0
  79. package/dist/types/utils/Normalizer.d.ts +3 -0
  80. package/dist/types/utils/Pool.d.ts +2 -0
  81. package/dist/types/utils/Registry.d.ts +3 -3
  82. package/dist/types/utils/StructuredData.d.ts +3 -1
  83. package/dist/types/utils/Types.d.ts +26 -0
  84. package/package.json +7 -7
  85. package/dist/CmpStr.esm.js.map +0 -1
  86. package/dist/CmpStr.esm.min.js.map +0 -1
  87. package/dist/CmpStr.umd.js.map +0 -1
  88. package/dist/CmpStr.umd.min.js.map +0 -1
  89. package/dist/cjs/CmpStr.cjs.map +0 -1
  90. package/dist/cjs/CmpStrAsync.cjs.map +0 -1
  91. package/dist/cjs/index.cjs.map +0 -1
  92. package/dist/cjs/metric/Cosine.cjs.map +0 -1
  93. package/dist/cjs/metric/DamerauLevenshtein.cjs.map +0 -1
  94. package/dist/cjs/metric/DiceSorensen.cjs.map +0 -1
  95. package/dist/cjs/metric/Hamming.cjs.map +0 -1
  96. package/dist/cjs/metric/Jaccard.cjs.map +0 -1
  97. package/dist/cjs/metric/JaroWinkler.cjs.map +0 -1
  98. package/dist/cjs/metric/LCS.cjs.map +0 -1
  99. package/dist/cjs/metric/Levenshtein.cjs.map +0 -1
  100. package/dist/cjs/metric/Metric.cjs.map +0 -1
  101. package/dist/cjs/metric/NeedlemanWunsch.cjs.map +0 -1
  102. package/dist/cjs/metric/QGram.cjs.map +0 -1
  103. package/dist/cjs/metric/SmithWaterman.cjs.map +0 -1
  104. package/dist/cjs/phonetic/Caverphone.cjs.map +0 -1
  105. package/dist/cjs/phonetic/Cologne.cjs.map +0 -1
  106. package/dist/cjs/phonetic/Metaphone.cjs.map +0 -1
  107. package/dist/cjs/phonetic/Phonetic.cjs.map +0 -1
  108. package/dist/cjs/phonetic/Soundex.cjs.map +0 -1
  109. package/dist/cjs/root.cjs.map +0 -1
  110. package/dist/cjs/utils/DeepMerge.cjs.map +0 -1
  111. package/dist/cjs/utils/DiffChecker.cjs.map +0 -1
  112. package/dist/cjs/utils/Filter.cjs.map +0 -1
  113. package/dist/cjs/utils/HashTable.cjs.map +0 -1
  114. package/dist/cjs/utils/Normalizer.cjs.map +0 -1
  115. package/dist/cjs/utils/Pool.cjs.map +0 -1
  116. package/dist/cjs/utils/Profiler.cjs.map +0 -1
  117. package/dist/cjs/utils/Registry.cjs.map +0 -1
  118. package/dist/cjs/utils/StructuredData.cjs.map +0 -1
  119. package/dist/cjs/utils/TextAnalyzer.cjs.map +0 -1
  120. package/dist/esm/CmpStr.mjs.map +0 -1
  121. package/dist/esm/CmpStrAsync.mjs.map +0 -1
  122. package/dist/esm/index.mjs.map +0 -1
  123. package/dist/esm/metric/Cosine.mjs.map +0 -1
  124. package/dist/esm/metric/DamerauLevenshtein.mjs.map +0 -1
  125. package/dist/esm/metric/DiceSorensen.mjs.map +0 -1
  126. package/dist/esm/metric/Hamming.mjs.map +0 -1
  127. package/dist/esm/metric/Jaccard.mjs.map +0 -1
  128. package/dist/esm/metric/JaroWinkler.mjs.map +0 -1
  129. package/dist/esm/metric/LCS.mjs.map +0 -1
  130. package/dist/esm/metric/Levenshtein.mjs.map +0 -1
  131. package/dist/esm/metric/Metric.mjs.map +0 -1
  132. package/dist/esm/metric/NeedlemanWunsch.mjs.map +0 -1
  133. package/dist/esm/metric/QGram.mjs.map +0 -1
  134. package/dist/esm/metric/SmithWaterman.mjs.map +0 -1
  135. package/dist/esm/phonetic/Caverphone.mjs.map +0 -1
  136. package/dist/esm/phonetic/Cologne.mjs.map +0 -1
  137. package/dist/esm/phonetic/Metaphone.mjs.map +0 -1
  138. package/dist/esm/phonetic/Phonetic.mjs.map +0 -1
  139. package/dist/esm/phonetic/Soundex.mjs.map +0 -1
  140. package/dist/esm/root.mjs.map +0 -1
  141. package/dist/esm/utils/DeepMerge.mjs.map +0 -1
  142. package/dist/esm/utils/DiffChecker.mjs.map +0 -1
  143. package/dist/esm/utils/Filter.mjs.map +0 -1
  144. package/dist/esm/utils/HashTable.mjs.map +0 -1
  145. package/dist/esm/utils/Normalizer.mjs.map +0 -1
  146. package/dist/esm/utils/Pool.mjs.map +0 -1
  147. package/dist/esm/utils/Profiler.mjs.map +0 -1
  148. package/dist/esm/utils/Registry.mjs.map +0 -1
  149. package/dist/esm/utils/StructuredData.mjs.map +0 -1
  150. package/dist/esm/utils/TextAnalyzer.mjs.map +0 -1
@@ -1,4 +1,5 @@
1
- // CmpStr v3.2.1 build-3439ccb-260130 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
+ import { ErrorUtil } from './Errors.mjs';
2
3
  import { HashTable } from './HashTable.mjs';
3
4
 
4
5
  class Normalizer {
@@ -15,42 +16,62 @@ class Normalizer {
15
16
  return Array.from(new Set(flags)).sort().join('');
16
17
  }
17
18
  static getPipeline(flags) {
18
- if (Normalizer.pipeline.has(flags)) return Normalizer.pipeline.get(flags);
19
- const { REGEX } = Normalizer;
20
- const steps = [
21
- ['d', (s) => s.normalize('NFD')],
22
- ['i', (s) => s.toLowerCase()],
23
- ['k', (s) => s.replace(REGEX.nonLetters, '')],
24
- ['n', (s) => s.replace(REGEX.nonNumbers, '')],
25
- ['r', (s) => s.replace(REGEX.doubleChars, '$1')],
26
- ['s', (s) => s.replace(REGEX.specialChars, '')],
27
- ['t', (s) => s.trim()],
28
- ['u', (s) => s.normalize('NFC')],
29
- ['w', (s) => s.replace(REGEX.whitespace, ' ')],
30
- ['x', (s) => s.normalize('NFKC')]
31
- ];
32
- const pipeline = steps
33
- .filter(([f]) => flags.includes(f))
34
- .map(([, fn]) => fn);
35
- const fn = (s) => pipeline.reduce((v, f) => f(v), s);
36
- Normalizer.pipeline.set(flags, fn);
37
- return fn;
19
+ return ErrorUtil.wrap(
20
+ () => {
21
+ if (Normalizer.pipeline.has(flags))
22
+ return Normalizer.pipeline.get(flags);
23
+ const { REGEX } = Normalizer;
24
+ const steps = [
25
+ ['d', (s) => s.normalize('NFD')],
26
+ ['i', (s) => s.toLowerCase()],
27
+ ['k', (s) => s.replace(REGEX.nonLetters, '')],
28
+ ['n', (s) => s.replace(REGEX.nonNumbers, '')],
29
+ ['r', (s) => s.replace(REGEX.doubleChars, '$1')],
30
+ ['s', (s) => s.replace(REGEX.specialChars, '')],
31
+ ['t', (s) => s.trim()],
32
+ ['u', (s) => s.normalize('NFC')],
33
+ ['w', (s) => s.replace(REGEX.whitespace, ' ')],
34
+ ['x', (s) => s.normalize('NFKC')]
35
+ ];
36
+ const pipeline = steps
37
+ .filter(([f]) => flags.includes(f))
38
+ .map(([, fn]) => fn);
39
+ const fn = (s) => pipeline.reduce((v, f) => f(v), s);
40
+ Normalizer.pipeline.set(flags, fn);
41
+ return fn;
42
+ },
43
+ `Failed to create normalization pipeline for flags: ${flags}`,
44
+ { flags }
45
+ );
38
46
  }
39
47
  static normalize(input, flags) {
40
- if (!flags || typeof flags !== 'string' || !input) return input;
41
- flags = this.canonicalFlags(flags);
42
- if (Array.isArray(input))
43
- return input.map((s) => Normalizer.normalize(s, flags));
44
- const key = Normalizer.cache.key(flags, [input]);
45
- if (key && Normalizer.cache.has(key)) return Normalizer.cache.get(key);
46
- const res = Normalizer.getPipeline(flags)(input);
47
- if (key) Normalizer.cache.set(key, res);
48
- return res;
48
+ return ErrorUtil.wrap(
49
+ () => {
50
+ if (!flags || typeof flags !== 'string' || !input) return input;
51
+ flags = this.canonicalFlags(flags);
52
+ if (Array.isArray(input))
53
+ return input.map((s) => Normalizer.normalize(s, flags));
54
+ const key = Normalizer.cache.key(flags, [input]);
55
+ if (key && Normalizer.cache.has(key)) return Normalizer.cache.get(key);
56
+ const res = Normalizer.getPipeline(flags)(input);
57
+ if (key) Normalizer.cache.set(key, res);
58
+ return res;
59
+ },
60
+ `Failed to normalize input with flags: ${flags}`,
61
+ { input, flags }
62
+ );
49
63
  }
50
64
  static async normalizeAsync(input, flags) {
51
- return await (Array.isArray(input)
52
- ? Promise.all(input.map((s) => Normalizer.normalize(s, flags)))
53
- : Promise.resolve(Normalizer.normalize(input, flags)));
65
+ return await ErrorUtil.wrapAsync(
66
+ async () => {
67
+ if (!flags || typeof flags !== 'string' || !input) return input;
68
+ return await (Array.isArray(input)
69
+ ? Promise.all(input.map((s) => Normalizer.normalize(s, flags)))
70
+ : Promise.resolve(Normalizer.normalize(input, flags)));
71
+ },
72
+ `Failed to asynchronously normalize input with flags: ${flags}`,
73
+ { input, flags }
74
+ );
54
75
  }
55
76
  static clear() {
56
77
  Normalizer.pipeline.clear();
@@ -59,4 +80,3 @@ class Normalizer {
59
80
  }
60
81
 
61
82
  export { Normalizer };
62
- //# sourceMappingURL=Normalizer.mjs.map
@@ -1,4 +1,6 @@
1
- // CmpStr v3.2.1 build-3439ccb-260130 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
+ import { CmpStrUsageError, ErrorUtil } from './Errors.mjs';
3
+
2
4
  class RingPool {
3
5
  maxSize;
4
6
  buffers = [];
@@ -7,22 +9,37 @@ class RingPool {
7
9
  this.maxSize = maxSize;
8
10
  }
9
11
  acquire(minSize, allowOversize) {
10
- const len = this.buffers.length;
11
- for (let i = 0; i < len; i++) {
12
- const idx = (this.pointer + i) & (len - 1);
13
- const item = this.buffers[idx];
14
- if (item.size >= minSize && (allowOversize || item.size === minSize)) {
15
- this.pointer = (idx + 1) & (len - 1);
16
- return item;
17
- }
18
- }
19
- return null;
12
+ return ErrorUtil.wrap(
13
+ () => {
14
+ const len = this.buffers.length;
15
+ for (let i = 0; i < len; i++) {
16
+ const idx = (this.pointer + i) & (len - 1);
17
+ const item = this.buffers[idx];
18
+ if (
19
+ item.size >= minSize &&
20
+ (allowOversize || item.size === minSize)
21
+ ) {
22
+ this.pointer = (idx + 1) & (len - 1);
23
+ return item;
24
+ }
25
+ }
26
+ return null;
27
+ },
28
+ `Failed to acquire buffer of size >= ${minSize} from pool`,
29
+ { minSize, allowOversize }
30
+ );
20
31
  }
21
32
  release(item) {
22
- if (this.buffers.length < this.maxSize)
23
- return void [this.buffers.push(item)];
24
- this.buffers[this.pointer] = item;
25
- this.pointer = (this.pointer + 1) % this.maxSize;
33
+ ErrorUtil.wrap(
34
+ () => {
35
+ if (this.buffers.length < this.maxSize)
36
+ return void [this.buffers.push(item)];
37
+ this.buffers[this.pointer] = item;
38
+ this.pointer = (this.pointer + 1) % this.maxSize;
39
+ },
40
+ `Failed to release buffer back to pool`,
41
+ { item }
42
+ );
26
43
  }
27
44
  clear() {
28
45
  this.buffers = [];
@@ -75,6 +92,8 @@ class Pool {
75
92
  }
76
93
  static acquire(type, size) {
77
94
  const CONFIG = this.CONFIG[type];
95
+ if (!CONFIG)
96
+ throw new CmpStrUsageError(`Unsupported pool type <${type}>`, { type });
78
97
  if (size > CONFIG.maxItemSize) return this.allocate(type, size);
79
98
  const item = this.POOLS[type].acquire(size, CONFIG.allowOversize);
80
99
  if (item)
@@ -85,10 +104,11 @@ class Pool {
85
104
  return sizes.map((size) => this.acquire(type, size));
86
105
  }
87
106
  static release(type, buffer, size) {
88
- if (size <= this.CONFIG[type].maxItemSize)
89
- this.POOLS[type].release({ buffer, size });
107
+ const CONFIG = this.CONFIG[type];
108
+ if (!CONFIG)
109
+ throw new CmpStrUsageError(`Unsupported pool type <${type}>`, { type });
110
+ if (size <= CONFIG.maxItemSize) this.POOLS[type].release({ buffer, size });
90
111
  }
91
112
  }
92
113
 
93
114
  export { Pool };
94
- //# sourceMappingURL=Pool.mjs.map
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.1 build-3439ccb-260130 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  class Profiler {
3
3
  active;
4
4
  static ENV;
@@ -79,4 +79,3 @@ class Profiler {
79
79
  }
80
80
 
81
81
  export { Profiler };
82
- //# sourceMappingURL=Profiler.mjs.map
@@ -1,20 +1,37 @@
1
- // CmpStr v3.2.1 build-3439ccb-260130 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
+ import { ErrorUtil, CmpStrNotFoundError } from './Errors.mjs';
3
+
2
4
  const registry = Object.create(null);
3
5
  const factory = Object.create(null);
4
6
  function Registry(reg, ctor) {
5
- if (reg in registry || reg in factory)
6
- throw new Error(
7
- `Registry <${reg}> already exists / overwriting is forbidden`
8
- );
7
+ ErrorUtil.assert(
8
+ !(reg in registry || reg in factory),
9
+ `Registry <${reg}> already exists / overwriting is forbidden`,
10
+ { registry: reg }
11
+ );
9
12
  const classes = Object.create(null);
10
13
  const service = Object.freeze({
11
14
  add(name, cls, update = false) {
12
- if (!(cls.prototype instanceof ctor))
13
- throw new TypeError(`Class must extend <${reg}>`);
14
- if (!update && name in classes)
15
- throw new Error(
16
- `Entry <${name}> already exists / use <update=true> to overwrite`
17
- );
15
+ ErrorUtil.assert(
16
+ typeof name === 'string' && name.length > 0,
17
+ `Class name must be a non-empty string`,
18
+ { registry: reg, name }
19
+ );
20
+ ErrorUtil.assert(
21
+ typeof cls === 'function',
22
+ `Class must be a constructor function`,
23
+ { registry: reg, class: cls }
24
+ );
25
+ ErrorUtil.assert(
26
+ cls.prototype instanceof ctor,
27
+ `Class must extend <${reg}>`,
28
+ { registry: reg, class: cls }
29
+ );
30
+ ErrorUtil.assert(
31
+ update || !(name in classes),
32
+ `Class <${name}> already exists / use <update=true> to overwrite`,
33
+ { registry: reg, name }
34
+ );
18
35
  classes[name] = cls;
19
36
  },
20
37
  remove(name) {
@@ -27,8 +44,16 @@ function Registry(reg, ctor) {
27
44
  return Object.keys(classes);
28
45
  },
29
46
  get(name) {
30
- if (!(name in classes))
31
- throw new Error(`Class <${name}> not registered for <${reg}>`);
47
+ ErrorUtil.assert(
48
+ typeof name === 'string' && name.length > 0,
49
+ `Class name must be a non-empty string`,
50
+ { registry: reg, name }
51
+ );
52
+ ErrorUtil.assert(
53
+ name in classes,
54
+ `Class <${name}> not registered for <${reg}>`,
55
+ { registry: reg, name }
56
+ );
32
57
  return classes[name];
33
58
  }
34
59
  });
@@ -38,19 +63,18 @@ function Registry(reg, ctor) {
38
63
  }
39
64
  function resolveCls(reg, cls) {
40
65
  if (!(reg in registry))
41
- throw new ReferenceError(`Registry <${reg}> does not exist`);
66
+ throw new CmpStrNotFoundError(`Registry <${reg}> does not exist`, {
67
+ registry: reg
68
+ });
42
69
  return typeof cls === 'string' ? registry[reg]?.get(cls) : cls;
43
70
  }
44
71
  function createFromRegistry(reg, cls, ...args) {
45
72
  cls = resolveCls(reg, cls);
46
- try {
47
- return new cls(...args);
48
- } catch (err) {
49
- throw new Error(`Cannot instantiate class <${cls.name ?? cls}>`, {
50
- cause: err
51
- });
52
- }
73
+ return ErrorUtil.wrap(
74
+ () => new cls(...args),
75
+ `Failed to create instance of class <${cls.name ?? cls}> from registry <${reg}>`,
76
+ { registry: reg, class: cls, args }
77
+ );
53
78
  }
54
79
 
55
80
  export { Registry, createFromRegistry, factory, registry, resolveCls };
56
- //# sourceMappingURL=Registry.mjs.map
@@ -1,4 +1,5 @@
1
- // CmpStr v3.2.1 build-3439ccb-260130 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
+ import { CmpStrValidationError, ErrorUtil } from './Errors.mjs';
2
3
  import { Pool } from './Pool.mjs';
3
4
 
4
5
  class StructuredData {
@@ -48,7 +49,7 @@ class StructuredData {
48
49
  raw: r.raw
49
50
  }));
50
51
  else
51
- throw new TypeError(
52
+ throw new CmpStrValidationError(
52
53
  'Unsupported result format for StructuredData normalization.'
53
54
  );
54
55
  return normalized.map((r, idx) => ({ ...r, __idx: idx }));
@@ -106,10 +107,18 @@ class StructuredData {
106
107
  );
107
108
  }
108
109
  performLookup(fn, extractedStrings, opt) {
109
- return this.finalizeLookup(fn(), extractedStrings, opt);
110
+ return ErrorUtil.wrap(
111
+ () => this.finalizeLookup(fn(), extractedStrings, opt),
112
+ 'StructuredData lookup failed',
113
+ { key: this.key }
114
+ );
110
115
  }
111
116
  async performLookupAsync(fn, extractedStrings, opt) {
112
- return this.finalizeLookup(await fn(), extractedStrings, opt);
117
+ return await ErrorUtil.wrapAsync(
118
+ async () => this.finalizeLookup(await fn(), extractedStrings, opt),
119
+ 'StructuredData async lookup failed',
120
+ { key: this.key }
121
+ );
113
122
  }
114
123
  lookup(fn, query, opt) {
115
124
  const b = this.extract();
@@ -150,4 +159,3 @@ class StructuredData {
150
159
  }
151
160
 
152
161
  export { StructuredData };
153
- //# sourceMappingURL=StructuredData.mjs.map
@@ -1,4 +1,4 @@
1
- // CmpStr v3.2.1 build-3439ccb-260130 by Paul Köhler @komed3 / MIT License
1
+ // CmpStr v3.2.2 build-bb61120-260311 by Paul Köhler @komed3 / MIT License
2
2
  class TextAnalyzer {
3
3
  static REGEX = {
4
4
  number: /\d/,
@@ -194,4 +194,3 @@ class TextAnalyzer {
194
194
  }
195
195
 
196
196
  export { TextAnalyzer };
197
- //# sourceMappingURL=TextAnalyzer.mjs.map
@@ -153,7 +153,8 @@ export declare class CmpStr<R = MetricRaw> {
153
153
  *
154
154
  * @param {string} cond - The condition to met
155
155
  * @param {any} [test] - Value to test for
156
- * @throws {Error} If the condition is not met
156
+ * @throws {CmpStrNotFoundError} - If the specified metric or phonetic algorithm is not found
157
+ * @throws {CmpStrInternalError} - If an unknown condition is specified
157
158
  */
158
159
  protected assert(cond: string, test?: any): void;
159
160
  /**
@@ -233,6 +234,7 @@ export declare class CmpStr<R = MetricRaw> {
233
234
  * @param {boolean} [raw=false] - Whether to return raw results
234
235
  * @param {boolean} [skip=false] - Whether to skip normalization and filtering
235
236
  * @returns {T} - The computed metric result
237
+ * @throws {CmpStrInternalError} - If the computation fails due to internal errors
236
238
  */
237
239
  protected compute<T extends MetricResult<R> | CmpStrResult | CmpStrResult[]>(a: MetricInput, b: MetricInput, opt?: CmpStrOptions, mode?: MetricMode, raw?: boolean, skip?: boolean): T;
238
240
  /**
@@ -242,6 +244,7 @@ export declare class CmpStr<R = MetricRaw> {
242
244
  * @param {MetricResult< R >} result - The metric result
243
245
  * @param {boolean} [raw] - Whether to return raw results
244
246
  * @returns {T} - The resolved result
247
+ * @throws {CmpStrInternalError} - If the output format cannot be resolved
245
248
  */
246
249
  protected output<T extends MetricResult<R> | CmpStrResult | CmpStrResult[]>(result: MetricResult<R>, raw?: boolean): T;
247
250
  /**
@@ -283,6 +286,7 @@ export declare class CmpStr<R = MetricRaw> {
283
286
  *
284
287
  * @param {string} opt - The serialized options
285
288
  * @returns {this}
289
+ * @throws {CmpStrValidationError} - If the provided string is not valid JSON
286
290
  */
287
291
  setSerializedOptions(opt: string): this;
288
292
  /**
@@ -106,6 +106,7 @@ export declare class CmpStrAsync<R = MetricRaw> extends CmpStr<R> {
106
106
  * @param {boolean} [raw=false] - Whether to return raw results
107
107
  * @param {boolean} [skip=false] - Whether to skip normalization and filtering
108
108
  * @returns {Promise< T >} - The computed metric result
109
+ * @throws {CmpStrInternalError} - If the computation fails due to internal errors
109
110
  */
110
111
  protected computeAsync<T extends MetricResult<R> | CmpStrResult | CmpStrResult[]>(a: MetricInput, b: MetricInput, opt?: CmpStrOptions, mode?: MetricMode, raw?: boolean, skip?: boolean): Promise<T>;
111
112
  /**
@@ -7,7 +7,7 @@
7
7
  * filtering, and text analysis. It is designed for both high-level application development
8
8
  * and research, offering a unified API for single, batch, and pairwise operations.
9
9
  *
10
- * Version: 3.2.1
10
+ * Version: 3.2.2
11
11
  * Author: Paul Köhler (komed3)
12
12
  * License: MIT
13
13
  *
@@ -41,11 +41,12 @@
41
41
  * For asynchronous workloads, use `CmpStrAsync`, which provides the same API with
42
42
  * Promise-based, non-blocking methods for large-scale or I/O-bound operations.
43
43
  *
44
- * @version 3.2.1
44
+ * @version 3.2.2
45
45
  * @author Paul Köhler (komed3)
46
46
  * @license MIT
47
47
  */
48
48
  export * from './utils/Types';
49
+ export type { CmpStrError, CmpStrValidationError, CmpStrNotFoundError, CmpStrUsageError, CmpStrInternalError } from './utils/Errors';
49
50
  export { CmpStr } from './CmpStr';
50
51
  export { CmpStrAsync } from './CmpStrAsync';
51
52
  export { DiffChecker } from './utils/DiffChecker';
@@ -83,7 +83,7 @@ export declare abstract class Metric<R = MetricRaw> {
83
83
  * @param {MetricInput} b - Second input string or array of strings
84
84
  * @param {MetricOptions} [opt] - Options for the metric computation
85
85
  * @param {boolean} [symmetric=false] - Whether the metric is symmetric (same result for inputs in any order)
86
- * @throws {Error} - If inputs `a` or `b` are empty
86
+ * @throws {CmpStrUsageError} - If the inputs are empty or invalid
87
87
  */
88
88
  constructor(metric: string, a: MetricInput, b: MetricInput, opt?: MetricOptions, symmetric?: boolean);
89
89
  /**
@@ -107,7 +107,7 @@ export declare abstract class Metric<R = MetricRaw> {
107
107
  * @param {number} n - Length of the second string
108
108
  * @param {number} maxLen - Maximum length of the strings
109
109
  * @returns {MetricCompute< R >} - The result of the metric computation
110
- * @throws {Error} - If not overridden in a subclass
110
+ * @throws {CmpStrInternalError} - If the method is not overridden in a subclass
111
111
  */
112
112
  protected compute(a: string, b: string, m: number, n: number, maxLen: number): MetricCompute<R>;
113
113
  /**
@@ -119,6 +119,7 @@ export declare abstract class Metric<R = MetricRaw> {
119
119
  * @param {number} i - Pointer to the first string
120
120
  * @param {number} j - Pointer to the second string
121
121
  * @returns {MetricResultSingle< R >} - The result of the metric computation
122
+ * @throws {CmpStrInternalError} - If the metric computation fails for the given inputs
122
123
  */
123
124
  private runSingle;
124
125
  /**
@@ -184,7 +185,7 @@ export declare abstract class Metric<R = MetricRaw> {
184
185
  *
185
186
  * @returns {boolean} - True if both inputs are arrays of equal length
186
187
  * @param {boolean} [safe=false] - If true, does not throw an error if lengths are not equal
187
- * @throws {Error} - If `safe` is false and the lengths of `a` and `b` are not equal
188
+ * @throws {CmpStrUsageError} - If `safe` is false and the lengths of `a` and `b` are not equal
188
189
  */
189
190
  isPairwise(safe?: boolean): boolean;
190
191
  /**
@@ -219,7 +220,7 @@ export declare abstract class Metric<R = MetricRaw> {
219
220
  *
220
221
  * @param {MetricMode} [mode] - The mode to run the metric in (optional)
221
222
  * @param {boolean} [clear=true] - Whether to clear previous results before running
222
- * @throws {Error} - If an unsupported mode is specified
223
+ * @throws {CmpStrInternalError} - If an unsupported mode is specified
223
224
  */
224
225
  run(mode?: MetricMode, clear?: boolean): void;
225
226
  /**
@@ -228,7 +229,7 @@ export declare abstract class Metric<R = MetricRaw> {
228
229
  * @param {MetricMode} [mode] - The mode to run the metric in (optional)
229
230
  * @param {boolean} [clear=true] - Whether to clear previous results before running
230
231
  * @returns {Promise<void>} - A promise that resolves when the metric computation is complete
231
- * @throws {Error} - If an unsupported mode is specified
232
+ * @throws {CmpStrInternalError} - If an unsupported mode is specified
232
233
  */
233
234
  runAsync(mode?: MetricMode, clear?: boolean): Promise<void>;
234
235
  /**
@@ -61,7 +61,7 @@ export declare abstract class Phonetic {
61
61
  *
62
62
  * @param {string} algo - The name of the algorithm (e.g. 'soundex')
63
63
  * @param {PhoneticOptions} [opt] - Options for the phonetic algorithm
64
- * @throws {Error} - If the requested mapping is not declared
64
+ * @throws {CmpStrNotFoundError} - If no mapping is specified or if the requested mapping is not declared
65
65
  */
66
66
  constructor(algo: string, opt?: PhoneticOptions);
67
67
  /**
@@ -149,6 +149,7 @@ export declare abstract class Phonetic {
149
149
  *
150
150
  * @param {string[]} words - An array of words to be processed
151
151
  * @returns {string[]} - An array of phonetic indices for the input words
152
+ * @throws {CmpStrInternalError} - If the phonetic index generation fails
152
153
  */
153
154
  protected loop(words: string[]): string[];
154
155
  /**
@@ -159,6 +160,7 @@ export declare abstract class Phonetic {
159
160
  *
160
161
  * @param {string[]} words - An array of words to be processed
161
162
  * @returns {Promise< string[] >} - A promise that resolves to an array of phonetic indices for the input words
163
+ * @throws {CmpStrInternalError} - If the asynchronous phonetic index generation fails
162
164
  */
163
165
  protected loopAsync(words: string[]): Promise<string[]>;
164
166
  /**
@@ -9,7 +9,7 @@
9
9
  * Please visit CmpStr's documentation for more information:
10
10
  * https://github.com/komed3/cmpstr/wiki/Extending-CmpStr
11
11
  *
12
- * @version 3.2.1
12
+ * @version 3.2.2
13
13
  * @author Paul Köhler (komed3)
14
14
  * @license MIT
15
15
  */
@@ -32,6 +32,7 @@ export { Metric, MetricCls, MetricRegistry } from './metric';
32
32
  */
33
33
  export { Phonetic, PhoneticCls, PhoneticMappingRegistry, PhoneticRegistry } from './phonetic';
34
34
  export * as DeepMerge from './utils/DeepMerge';
35
+ export * as CmpStrError from './utils/Errors';
35
36
  export { Filter } from './utils/Filter';
36
37
  export { Hasher, HashTable } from './utils/HashTable';
37
38
  export { Pool } from './utils/Pool';
@@ -47,7 +47,7 @@ export declare function has<T extends Record<string, any>>(t: T, path: string):
47
47
  * @param {string} path - The path string, e.g. `a.b.c`
48
48
  * @param {any} value - The value to set at the specified path
49
49
  * @returns {T} - The modified object with the value set at the specified path
50
- * @throws {Error} - Throws an error if the key is not a valid identifier
50
+ * @throws {CmpStrUsageError} - If the path is invalid or if a non-object value is encountered along the path
51
51
  */
52
52
  export declare function set<T extends Record<string, any>>(t: T, path: string, value: any): T;
53
53
  /**