cmpstr 3.2.0 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +26 -18
  2. package/dist/CmpStr.esm.js +490 -220
  3. package/dist/CmpStr.esm.min.js +2 -3
  4. package/dist/CmpStr.umd.js +489 -220
  5. package/dist/CmpStr.umd.min.js +2 -3
  6. package/dist/cjs/CmpStr.cjs +58 -36
  7. package/dist/cjs/CmpStrAsync.cjs +30 -24
  8. package/dist/cjs/index.cjs +1 -2
  9. package/dist/cjs/metric/Cosine.cjs +1 -2
  10. package/dist/cjs/metric/DamerauLevenshtein.cjs +1 -2
  11. package/dist/cjs/metric/DiceSorensen.cjs +1 -2
  12. package/dist/cjs/metric/Hamming.cjs +5 -4
  13. package/dist/cjs/metric/Jaccard.cjs +1 -2
  14. package/dist/cjs/metric/JaroWinkler.cjs +1 -2
  15. package/dist/cjs/metric/LCS.cjs +1 -2
  16. package/dist/cjs/metric/Levenshtein.cjs +1 -2
  17. package/dist/cjs/metric/Metric.cjs +57 -38
  18. package/dist/cjs/metric/NeedlemanWunsch.cjs +1 -2
  19. package/dist/cjs/metric/QGram.cjs +1 -2
  20. package/dist/cjs/metric/SmithWaterman.cjs +1 -2
  21. package/dist/cjs/phonetic/Caverphone.cjs +1 -2
  22. package/dist/cjs/phonetic/Cologne.cjs +1 -2
  23. package/dist/cjs/phonetic/Metaphone.cjs +1 -2
  24. package/dist/cjs/phonetic/Phonetic.cjs +55 -35
  25. package/dist/cjs/phonetic/Soundex.cjs +1 -2
  26. package/dist/cjs/root.cjs +3 -2
  27. package/dist/cjs/utils/DeepMerge.cjs +10 -5
  28. package/dist/cjs/utils/DiffChecker.cjs +1 -2
  29. package/dist/cjs/utils/Errors.cjs +103 -0
  30. package/dist/cjs/utils/Filter.cjs +56 -27
  31. package/dist/cjs/utils/HashTable.cjs +1 -2
  32. package/dist/cjs/utils/Normalizer.cjs +54 -34
  33. package/dist/cjs/utils/Pool.cjs +42 -18
  34. package/dist/cjs/utils/Profiler.cjs +1 -2
  35. package/dist/cjs/utils/Registry.cjs +46 -22
  36. package/dist/cjs/utils/StructuredData.cjs +13 -5
  37. package/dist/cjs/utils/TextAnalyzer.cjs +1 -2
  38. package/dist/esm/CmpStr.mjs +56 -32
  39. package/dist/esm/CmpStrAsync.mjs +26 -20
  40. package/dist/esm/index.mjs +1 -2
  41. package/dist/esm/metric/Cosine.mjs +1 -2
  42. package/dist/esm/metric/DamerauLevenshtein.mjs +1 -2
  43. package/dist/esm/metric/DiceSorensen.mjs +1 -2
  44. package/dist/esm/metric/Hamming.mjs +5 -4
  45. package/dist/esm/metric/Jaccard.mjs +1 -2
  46. package/dist/esm/metric/JaroWinkler.mjs +1 -2
  47. package/dist/esm/metric/LCS.mjs +1 -2
  48. package/dist/esm/metric/Levenshtein.mjs +1 -2
  49. package/dist/esm/metric/Metric.mjs +59 -38
  50. package/dist/esm/metric/NeedlemanWunsch.mjs +1 -2
  51. package/dist/esm/metric/QGram.mjs +1 -2
  52. package/dist/esm/metric/SmithWaterman.mjs +1 -2
  53. package/dist/esm/phonetic/Caverphone.mjs +1 -2
  54. package/dist/esm/phonetic/Cologne.mjs +1 -2
  55. package/dist/esm/phonetic/Metaphone.mjs +1 -2
  56. package/dist/esm/phonetic/Phonetic.mjs +55 -35
  57. package/dist/esm/phonetic/Soundex.mjs +1 -2
  58. package/dist/esm/root.mjs +3 -2
  59. package/dist/esm/utils/DeepMerge.mjs +10 -5
  60. package/dist/esm/utils/DiffChecker.mjs +1 -2
  61. package/dist/esm/utils/Errors.mjs +103 -0
  62. package/dist/esm/utils/Filter.mjs +56 -27
  63. package/dist/esm/utils/HashTable.mjs +1 -2
  64. package/dist/esm/utils/Normalizer.mjs +54 -34
  65. package/dist/esm/utils/Pool.mjs +38 -18
  66. package/dist/esm/utils/Profiler.mjs +1 -2
  67. package/dist/esm/utils/Registry.mjs +46 -22
  68. package/dist/esm/utils/StructuredData.mjs +13 -5
  69. package/dist/esm/utils/TextAnalyzer.mjs +1 -2
  70. package/dist/types/CmpStr.d.ts +12 -6
  71. package/dist/types/CmpStrAsync.d.ts +6 -4
  72. package/dist/types/index.d.ts +3 -2
  73. package/dist/types/metric/Cosine.d.ts +2 -1
  74. package/dist/types/metric/DamerauLevenshtein.d.ts +2 -1
  75. package/dist/types/metric/DiceSorensen.d.ts +2 -1
  76. package/dist/types/metric/Hamming.d.ts +2 -1
  77. package/dist/types/metric/Jaccard.d.ts +2 -1
  78. package/dist/types/metric/JaroWinkler.d.ts +2 -1
  79. package/dist/types/metric/LCS.d.ts +2 -1
  80. package/dist/types/metric/Levenshtein.d.ts +2 -1
  81. package/dist/types/metric/Metric.d.ts +7 -5
  82. package/dist/types/metric/NeedlemanWunsch.d.ts +2 -1
  83. package/dist/types/metric/QGram.d.ts +2 -1
  84. package/dist/types/metric/SmithWaterman.d.ts +2 -1
  85. package/dist/types/metric/index.d.ts +1 -0
  86. package/dist/types/phonetic/Caverphone.d.ts +2 -1
  87. package/dist/types/phonetic/Cologne.d.ts +2 -1
  88. package/dist/types/phonetic/Metaphone.d.ts +2 -1
  89. package/dist/types/phonetic/Phonetic.d.ts +4 -1
  90. package/dist/types/phonetic/Soundex.d.ts +2 -1
  91. package/dist/types/phonetic/index.d.ts +1 -0
  92. package/dist/types/root.d.ts +2 -1
  93. package/dist/types/utils/DeepMerge.d.ts +3 -2
  94. package/dist/types/utils/DiffChecker.d.ts +2 -1
  95. package/dist/types/utils/Errors.d.ts +137 -0
  96. package/dist/types/utils/Filter.d.ts +33 -22
  97. package/dist/types/utils/HashTable.d.ts +2 -1
  98. package/dist/types/utils/Normalizer.d.ts +5 -1
  99. package/dist/types/utils/Pool.d.ts +4 -1
  100. package/dist/types/utils/Profiler.d.ts +3 -2
  101. package/dist/types/utils/Registry.d.ts +5 -4
  102. package/dist/types/utils/StructuredData.d.ts +5 -2
  103. package/dist/types/utils/TextAnalyzer.d.ts +2 -1
  104. package/dist/types/utils/Types.d.ts +34 -2
  105. package/package.json +10 -7
  106. package/dist/CmpStr.esm.js.map +0 -1
  107. package/dist/CmpStr.esm.min.js.map +0 -1
  108. package/dist/CmpStr.umd.js.map +0 -1
  109. package/dist/CmpStr.umd.min.js.map +0 -1
  110. package/dist/cjs/CmpStr.cjs.map +0 -1
  111. package/dist/cjs/CmpStrAsync.cjs.map +0 -1
  112. package/dist/cjs/index.cjs.map +0 -1
  113. package/dist/cjs/metric/Cosine.cjs.map +0 -1
  114. package/dist/cjs/metric/DamerauLevenshtein.cjs.map +0 -1
  115. package/dist/cjs/metric/DiceSorensen.cjs.map +0 -1
  116. package/dist/cjs/metric/Hamming.cjs.map +0 -1
  117. package/dist/cjs/metric/Jaccard.cjs.map +0 -1
  118. package/dist/cjs/metric/JaroWinkler.cjs.map +0 -1
  119. package/dist/cjs/metric/LCS.cjs.map +0 -1
  120. package/dist/cjs/metric/Levenshtein.cjs.map +0 -1
  121. package/dist/cjs/metric/Metric.cjs.map +0 -1
  122. package/dist/cjs/metric/NeedlemanWunsch.cjs.map +0 -1
  123. package/dist/cjs/metric/QGram.cjs.map +0 -1
  124. package/dist/cjs/metric/SmithWaterman.cjs.map +0 -1
  125. package/dist/cjs/phonetic/Caverphone.cjs.map +0 -1
  126. package/dist/cjs/phonetic/Cologne.cjs.map +0 -1
  127. package/dist/cjs/phonetic/Metaphone.cjs.map +0 -1
  128. package/dist/cjs/phonetic/Phonetic.cjs.map +0 -1
  129. package/dist/cjs/phonetic/Soundex.cjs.map +0 -1
  130. package/dist/cjs/root.cjs.map +0 -1
  131. package/dist/cjs/utils/DeepMerge.cjs.map +0 -1
  132. package/dist/cjs/utils/DiffChecker.cjs.map +0 -1
  133. package/dist/cjs/utils/Filter.cjs.map +0 -1
  134. package/dist/cjs/utils/HashTable.cjs.map +0 -1
  135. package/dist/cjs/utils/Normalizer.cjs.map +0 -1
  136. package/dist/cjs/utils/Pool.cjs.map +0 -1
  137. package/dist/cjs/utils/Profiler.cjs.map +0 -1
  138. package/dist/cjs/utils/Registry.cjs.map +0 -1
  139. package/dist/cjs/utils/StructuredData.cjs.map +0 -1
  140. package/dist/cjs/utils/TextAnalyzer.cjs.map +0 -1
  141. package/dist/esm/CmpStr.mjs.map +0 -1
  142. package/dist/esm/CmpStrAsync.mjs.map +0 -1
  143. package/dist/esm/index.mjs.map +0 -1
  144. package/dist/esm/metric/Cosine.mjs.map +0 -1
  145. package/dist/esm/metric/DamerauLevenshtein.mjs.map +0 -1
  146. package/dist/esm/metric/DiceSorensen.mjs.map +0 -1
  147. package/dist/esm/metric/Hamming.mjs.map +0 -1
  148. package/dist/esm/metric/Jaccard.mjs.map +0 -1
  149. package/dist/esm/metric/JaroWinkler.mjs.map +0 -1
  150. package/dist/esm/metric/LCS.mjs.map +0 -1
  151. package/dist/esm/metric/Levenshtein.mjs.map +0 -1
  152. package/dist/esm/metric/Metric.mjs.map +0 -1
  153. package/dist/esm/metric/NeedlemanWunsch.mjs.map +0 -1
  154. package/dist/esm/metric/QGram.mjs.map +0 -1
  155. package/dist/esm/metric/SmithWaterman.mjs.map +0 -1
  156. package/dist/esm/phonetic/Caverphone.mjs.map +0 -1
  157. package/dist/esm/phonetic/Cologne.mjs.map +0 -1
  158. package/dist/esm/phonetic/Metaphone.mjs.map +0 -1
  159. package/dist/esm/phonetic/Phonetic.mjs.map +0 -1
  160. package/dist/esm/phonetic/Soundex.mjs.map +0 -1
  161. package/dist/esm/root.mjs.map +0 -1
  162. package/dist/esm/utils/DeepMerge.mjs.map +0 -1
  163. package/dist/esm/utils/DiffChecker.mjs.map +0 -1
  164. package/dist/esm/utils/Filter.mjs.map +0 -1
  165. package/dist/esm/utils/HashTable.mjs.map +0 -1
  166. package/dist/esm/utils/Normalizer.mjs.map +0 -1
  167. package/dist/esm/utils/Pool.mjs.map +0 -1
  168. package/dist/esm/utils/Profiler.mjs.map +0 -1
  169. package/dist/esm/utils/Registry.mjs.map +0 -1
  170. package/dist/esm/utils/StructuredData.mjs.map +0 -1
  171. package/dist/esm/utils/TextAnalyzer.mjs.map +0 -1
@@ -8,7 +8,8 @@
8
8
  * entirely, including gaps. It is commonly used in bioinformatics for sequence
9
9
  * alignment.
10
10
  *
11
- * @module Metric/NeedlemanWunsch
11
+ * @module Metric
12
+ * @name NeedlemanWunsch
12
13
  * @author Paul Köhler (komed3)
13
14
  * @license MIT
14
15
  */
@@ -12,7 +12,8 @@
12
12
  * This metric is widely used in approximate string matching, information retrieval,
13
13
  * and computational linguistics.
14
14
  *
15
- * @module Metric/QGramSimilarity
15
+ * @module Metric
16
+ * @name QGramSimilarity
16
17
  * @author Paul Köhler (komed3)
17
18
  * @license MIT
18
19
  */
@@ -10,7 +10,8 @@
10
10
  * algorithm compares segments of all possible lengths and optimizes the similarity
11
11
  * measure.
12
12
  *
13
- * @module Metric/SmithWatermanDistance
13
+ * @module Metric
14
+ * @name SmithWatermanDistance
14
15
  * @author Paul Köhler (komed3)
15
16
  * @license MIT
16
17
  */
@@ -24,6 +24,7 @@
24
24
  * pooling system to manage resources effectively, ensuring minimal overhead
25
25
  * and maximum performance.
26
26
  *
27
+ * @module Metric
27
28
  * @author Paul Köhler (komed3)
28
29
  * @license MIT
29
30
  */
@@ -12,7 +12,8 @@
12
12
  * It converts words into a standardized phonetic code, allowing for variations
13
13
  * in spelling and pronunciation to be matched.
14
14
  *
15
- * @module Phonetic/Caverphone
15
+ * @module Phonetic
16
+ * @name Caverphone
16
17
  * @author Paul Köhler (komed3)
17
18
  * @license MIT
18
19
  */
@@ -17,7 +17,8 @@
17
17
  * The Cologne phonetic algorithm works by mapping letters to digits, ignoring
18
18
  * certain letters, and applying specific rules to handle character combinations.
19
19
  *
20
- * @module Phonetic/Cologne
20
+ * @module Phonetic
21
+ * @name Cologne
21
22
  * @author Paul Köhler (komed3)
22
23
  * @license MIT
23
24
  */
@@ -14,7 +14,8 @@
14
14
  * transform input words into their Metaphone code. The algorithm drops or transforms
15
15
  * letters according to context-sensitive rules, and only retains vowels at the start.
16
16
  *
17
- * @module Phonetic/Metaphone
17
+ * @module Phonetic
18
+ * @name Metaphone
18
19
  * @author Paul Köhler (komed3)
19
20
  * @license MIT
20
21
  */
@@ -19,6 +19,7 @@
19
19
  * phonetic algorithms by extending the abstract class.
20
20
  *
21
21
  * @module Phonetic
22
+ * @name Phonetic
22
23
  * @author Paul Köhler (komed3)
23
24
  * @license MIT
24
25
  */
@@ -60,7 +61,7 @@ export declare abstract class Phonetic {
60
61
  *
61
62
  * @param {string} algo - The name of the algorithm (e.g. 'soundex')
62
63
  * @param {PhoneticOptions} [opt] - Options for the phonetic algorithm
63
- * @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
64
65
  */
65
66
  constructor(algo: string, opt?: PhoneticOptions);
66
67
  /**
@@ -148,6 +149,7 @@ export declare abstract class Phonetic {
148
149
  *
149
150
  * @param {string[]} words - An array of words to be processed
150
151
  * @returns {string[]} - An array of phonetic indices for the input words
152
+ * @throws {CmpStrInternalError} - If the phonetic index generation fails
151
153
  */
152
154
  protected loop(words: string[]): string[];
153
155
  /**
@@ -158,6 +160,7 @@ export declare abstract class Phonetic {
158
160
  *
159
161
  * @param {string[]} words - An array of words to be processed
160
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
161
164
  */
162
165
  protected loopAsync(words: string[]): Promise<string[]>;
163
166
  /**
@@ -18,7 +18,8 @@
18
18
  * consonants. It outputs an array of strings that represents the phonetic code
19
19
  * of the input, typically limited to the length of four characters.
20
20
  *
21
- * @module Phonetic/Soundex
21
+ * @module Phonetic
22
+ * @name Soundex
22
23
  * @author Paul Köhler (komed3)
23
24
  * @license MIT
24
25
  */
@@ -21,6 +21,7 @@
21
21
  * - Consistent interface for accessing, listing, and managing phonetic algorithms
22
22
  * - Ensures that all phonetic algorithms are available for use in the CmpStr API
23
23
  *
24
+ * @module Phonetic
24
25
  * @author Paul Köhler (komed3)
25
26
  * @license MIT
26
27
  */
@@ -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.0
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';
@@ -14,7 +14,8 @@
14
14
  * - `has`: Check whether a path exists
15
15
  * - `rmv`: Delete a value at a path
16
16
  *
17
- * @module Utils/DeepMerge
17
+ * @module Utils
18
+ * @name DeepMerge
18
19
  * @author Paul Köhler
19
20
  * @license MIT
20
21
  */
@@ -46,7 +47,7 @@ export declare function has<T extends Record<string, any>>(t: T, path: string):
46
47
  * @param {string} path - The path string, e.g. `a.b.c`
47
48
  * @param {any} value - The value to set at the specified path
48
49
  * @returns {T} - The modified object with the value set at the specified path
49
- * @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
50
51
  */
51
52
  export declare function set<T extends Record<string, any>>(t: T, path: string, value: any): T;
52
53
  /**
@@ -20,7 +20,8 @@
20
20
  * - Change magnitude calculation (relative to group or line)
21
21
  * - Expand-all mode for full file context
22
22
  *
23
- * @module Utils/DiffChecker
23
+ * @module Utils
24
+ * @name DiffChecker
24
25
  * @author Paul Köhler (komed3)
25
26
  * @license MIT
26
27
  */
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Error Utilities
3
+ * src/utils/Errors.ts
4
+ *
5
+ * This module provides a small hierarchy of error classes and helper methods
6
+ * that standardize error creation and formatting across the CmpStr project.
7
+ * It improves on vanilla JavaScript errors by adding codes, structured metadata,
8
+ * and consistent `toString()` / `toJSON()` output while keeping the original
9
+ * message text intact.
10
+ *
11
+ * The error classes are designed to be lightweight and fast, while still
12
+ * providing useful context for debugging (including optional `cause` chaining).
13
+ *
14
+ * @module Utils
15
+ * @name Errors
16
+ * @author Paul Köhler (komed3)
17
+ * @license MIT
18
+ */
19
+ import type { CmpStrErrorJSON, CmpStrErrorMeta } from './Types';
20
+ /**
21
+ * Base error class for CmpStr.
22
+ *
23
+ * It provides a standard `code` field and a consistent `toString()` / `toJSON()`
24
+ * output without changing the original error message expectations.
25
+ */
26
+ export declare class CmpStrError extends Error {
27
+ /** A short, machine-readable error code */
28
+ readonly code: string;
29
+ /** Optional structured metadata for the error */
30
+ readonly meta?: CmpStrErrorMeta;
31
+ /** Optional cause (native JS Error chaining) */
32
+ readonly cause?: unknown;
33
+ /** Timestamp when the error was created (ISO 8601) */
34
+ readonly when: string;
35
+ /**
36
+ * Constructor for CmpStrError.
37
+ *
38
+ * Will construct an error with a code, message, optional metadata, and optional cause.
39
+ *
40
+ * @param {string} code - A short, machine-readable error code
41
+ * @param {string} message - The error message (human-readable)
42
+ * @param {CmpStrErrorMeta} [meta] - Optional structured metadata for the error
43
+ * @param {unknown} [cause] - Optional cause (native JS Error chaining)
44
+ */
45
+ constructor(code: string, message: string, meta?: CmpStrErrorMeta, cause?: unknown);
46
+ /**
47
+ * Serialize the error into a plain object for JSON output.
48
+ */
49
+ toJSON(): CmpStrErrorJSON;
50
+ /**
51
+ * Pretty string representation of the error.
52
+ *
53
+ * @param {boolean} [stack=false] - Whether to include the stack trace in the output
54
+ */
55
+ toString(stack?: boolean): string;
56
+ }
57
+ /**
58
+ * Error thrown when user input (options, arguments) is invalid.
59
+ */
60
+ export declare class CmpStrValidationError extends CmpStrError {
61
+ constructor(message: string, meta?: CmpStrErrorMeta, cause?: unknown);
62
+ }
63
+ /**
64
+ * Error thrown when a requested resource is missing or not found.
65
+ */
66
+ export declare class CmpStrNotFoundError extends CmpStrError {
67
+ constructor(message: string, meta?: CmpStrErrorMeta, cause?: unknown);
68
+ }
69
+ /**
70
+ * Error thrown for incorrect usage or invalid state (assertions).
71
+ */
72
+ export declare class CmpStrUsageError extends CmpStrError {
73
+ constructor(message: string, meta?: CmpStrErrorMeta, cause?: unknown);
74
+ }
75
+ /**
76
+ * Error thrown for internal failures that should not happen under normal usage.
77
+ */
78
+ export declare class CmpStrInternalError extends CmpStrError {
79
+ constructor(message: string, meta?: CmpStrErrorMeta, cause?: unknown);
80
+ }
81
+ /**
82
+ * Helper utilities for throwing and formatting errors.
83
+ *
84
+ * Provides methods for asserting conditions, wrapping unknown errors, and formatting
85
+ * errors into readable strings. This centralizes error handling logic and ensures
86
+ * consistent error messages across the codebase.
87
+ */
88
+ export declare class ErrorUtil {
89
+ /**
90
+ * Throw a `CmpStrUsageError` if a condition is not met.
91
+ *
92
+ * @param {boolean} condition - The condition to assert
93
+ * @param {string} message - The error message to throw if the condition is false
94
+ * @param {CmpStrErrorMeta} [meta] - Optional structured metadata for the error
95
+ * @throws {CmpStrUsageError} - If the condition is false
96
+ */
97
+ static assert(condition: boolean, message: string, meta?: CmpStrErrorMeta): asserts condition;
98
+ /**
99
+ * Wrap an unknown error into a `CmpStrInternalError`.
100
+ *
101
+ * @param {unknown} err - The error to wrap
102
+ * @param {string} message - The error message to use for the wrapped error
103
+ * @param {CmpStrErrorMeta} [meta] - Optional structured metadata for the error
104
+ * @throws {CmpStrInternalError} - Always throws a new `CmpStrInternalError` wrapping the original error
105
+ */
106
+ static create(err: unknown, message: string, meta?: CmpStrErrorMeta): never;
107
+ /**
108
+ * Format any error into a readable string.
109
+ *
110
+ * @param {unknown} err - The error to format
111
+ * @returns {string} - A formatted string representation of the error
112
+ */
113
+ static format(err: unknown): string;
114
+ /**
115
+ * Execute a synchronous operation and wrap any exception as a `CmpStrInternalError`.
116
+ *
117
+ * This is used to avoid repeating try/catch blocks and to add consistent context
118
+ * to unexpected failures while preserving the original error as `cause`.
119
+ *
120
+ * @param {() => T} fn - The function to execute
121
+ * @param {string} message - The error message to use if an exception is thrown
122
+ * @param {CmpStrErrorMeta} [meta] - Optional structured metadata for the error
123
+ * @return {T} The result of the function if it executes successfully
124
+ * @throws {CmpStrInternalError} - If the function throws an error, it will be wrapped and re-thrown as a `CmpStrInternalError`
125
+ */
126
+ static wrap<T>(fn: () => T, message: string, meta?: CmpStrErrorMeta): T;
127
+ /**
128
+ * Execute an asynchronous operation and wrap any exception as a `CmpStrInternalError`.
129
+ *
130
+ * @param {() => Promise< T >} fn - The asynchronous function to execute
131
+ * @param {string} message - The error message to use if an exception is thrown
132
+ * @param {CmpStrErrorMeta} [meta] - Optional structured metadata for the error
133
+ * @return {Promise<T>} A promise that resolves to the result of the function if it executes successfully
134
+ * @throws {CmpStrInternalError} - If the function throws an error, it will be wrapped and re-thrown as a `CmpStrInternalError`
135
+ */
136
+ static wrapAsync<T>(fn: () => Promise<T>, message: string, meta?: CmpStrErrorMeta): Promise<T>;
137
+ }
@@ -7,11 +7,12 @@
7
7
  * applied to input strings. Each filter has an id, a function, a priority, and options
8
8
  * for activation and overrideability.
9
9
  *
10
- * @module Utils/Filter
10
+ * @module Utils
11
+ * @name Filter
11
12
  * @author Paul Köhler (komed3)
12
13
  * @license MIT
13
14
  */
14
- import type { FilterFn, FilterOptions } from './Types';
15
+ import type { FilterFn, FilterHooks, FilterOptions } from './Types';
15
16
  /**
16
17
  * The Filter class provides a way to manage and apply filters to strings based on hooks.
17
18
  */
@@ -30,82 +31,92 @@ export declare class Filter {
30
31
  * Retrieves the compiled filter function for a given hook.
31
32
  * If the function is not cached, it compiles it from the active filters.
32
33
  *
33
- * @param {string} hook - The name of the hook
34
+ * @param {FilterHooks} hook - The name of the hook
34
35
  * @returns {FilterFn} - The compiled filter function for the hook
36
+ * @throws {CmpStrInternalError} - Throws an error if the pipeline compilation fails
35
37
  */
36
38
  private static getPipeline;
37
39
  /**
38
40
  * Checks if a filter exists for a given hook and id.
39
41
  *
40
- * @param {string} hook - The name of the hook
42
+ * @param {FilterHooks} hook - The name of the hook
41
43
  * @param {string} id - The id of the filter
42
44
  * @returns {boolean} - Returns true if the filter exists, false otherwise
43
45
  */
44
- static has(hook: string, id: string): boolean;
46
+ static has(hook: FilterHooks, id: string): boolean;
45
47
  /**
46
48
  * Adds a filter to the specified hook.
47
49
  *
48
- * @param {string} hook - The name of the hook
50
+ * @param {FilterHooks} hook - The name of the hook
49
51
  * @param {string} id - The id of the filter
50
52
  * @param {FilterFn} fn - The filter function
51
53
  * @param {FilterOptions} [opt] - Additional options for the filter
52
- * @returns {boolean} - Returns true if the filter was added, false if it was not added due to override restrictions
54
+ * @returns {boolean} - Returns true if the filter was added,
55
+ * false if it was not added due to override restrictions
56
+ * @throws {CmpStrInternalError} - Throws an error if there is an issue adding the filter
53
57
  */
54
- static add(hook: string, id: string, fn: FilterFn, opt?: FilterOptions): boolean;
58
+ static add(hook: FilterHooks, id: string, fn: FilterFn, opt?: FilterOptions): boolean;
55
59
  /**
56
60
  * Removes a filter by its hook and id.
57
61
  *
58
- * @param {string} hook - The name of the hook
62
+ * @param {FilterHooks} hook - The name of the hook
59
63
  * @param {string} id - The id of the filter
60
64
  * @returns {boolean} - Returns true if the filter was removed, false if it was not found
61
65
  */
62
- static remove(hook: string, id: string): boolean;
66
+ static remove(hook: FilterHooks, id: string): boolean;
63
67
  /**
64
68
  * Pauses a filter by its hook and id.
65
69
  *
66
- * @param {string} hook - The name of the hook
70
+ * @param {FilterHooks} hook - The name of the hook
67
71
  * @param {string} id - The id of the filter
68
72
  * @returns {boolean} - Returns true if the filter was paused, false if it was not found
69
73
  */
70
- static pause(hook: string, id: string): boolean;
74
+ static pause(hook: FilterHooks, id: string): boolean;
71
75
  /**
72
76
  * Resumes a filter by its hook and id.
73
77
  *
74
- * @param {string} hook - The name of the hook
78
+ * @param {FilterHooks} hook - The name of the hook
75
79
  * @param {string} id - The id of the filter
76
80
  * @returns {boolean} - Returns true if the filter was resumed, false if it was not found
77
81
  */
78
- static resume(hook: string, id: string): boolean;
82
+ static resume(hook: FilterHooks, id: string): boolean;
79
83
  /**
80
84
  * Lists all filters for a given hook.
81
85
  *
82
- * @param {string} hook - The name of the hook
86
+ * @param {FilterHooks} hook - The name of the hook
83
87
  * @param {boolean} active - If true, only list active filters
84
88
  * @returns {string[]} - An array of filter ids
85
89
  */
86
- static list(hook: string, active?: boolean): string[];
90
+ static list(hook: FilterHooks, active?: boolean): string[];
87
91
  /**
88
92
  * Applies all active filters for a given hook to the input string(s).
89
93
  *
90
- * @param {string} hook - The name of the hook
94
+ * @param {FilterHooks} hook - The name of the hook
91
95
  * @param {string | string[]} input - The input string(s) to be filtered
92
96
  * @returns {string | string[]} - The filtered string(s)
97
+ * @throws {CmpStrInternalError} - Throws an error if there is an issue applying the filters
93
98
  */
94
- static apply(hook: string, input: string | string[]): string | string[];
99
+ static apply(hook: FilterHooks, input: string | string[]): string | string[];
95
100
  /**
96
101
  * Applies all active filters for a given hook to the input string(s) asynchronously.
97
102
  * Each filter function may return a Promise or a plain string; all are awaited in order.
98
103
  *
99
- * @param {string} hook - The name of the hook
104
+ * @param {FilterHooks} hook - The name of the hook
100
105
  * @param {string | string[]} input - The input string(s) to be filtered
101
106
  * @returns {Promise< string | string[] >} - The filtered string(s)
107
+ * @throws {CmpStrInternalError} - Throws an error if there is an issue applying the filters
102
108
  */
103
- static applyAsync(hook: string, input: string | string[]): Promise<string | string[]>;
109
+ static applyAsync(hook: FilterHooks, input: string | string[]): Promise<string | string[]>;
104
110
  /**
105
111
  * Clears all filters or filters for a specific hook.
106
112
  * If no hook is provided, clear all filters
107
113
  *
108
- * @param {string} [hook] - Optional name of the hook to clear filters for
114
+ * @param {FilterHooks} [hook] - Optional name of the hook to clear filters for
109
115
  */
110
- static clear(hook?: string): void;
116
+ static clear(hook?: FilterHooks): void;
117
+ /**
118
+ * Clears the entire filter pipeline cache.
119
+ * This forces recompilation of all pipelines on next application.
120
+ */
121
+ static clearPipeline(): void;
111
122
  }
@@ -15,7 +15,8 @@
15
15
  * The key() method supports any number of string arguments, enabling flexible cache keys
16
16
  * for different use cases (e.g. normalization, metrics, etc.).
17
17
  *
18
- * @module Utils/HashTable
18
+ * @module Utils
19
+ * @name HashTable
19
20
  * @author Paul Köhler (komed3)
20
21
  * @license MIT
21
22
  */
@@ -22,7 +22,8 @@
22
22
  * 'n' :: Remove non-number characters
23
23
  * 'i' :: Case insensitive (convert to lowercase)
24
24
  *
25
- * @module Utils/Normalizer
25
+ * @module Utils
26
+ * @name Normalizer
26
27
  * @author Paul Köhler (komed3)
27
28
  * @license MIT
28
29
  */
@@ -56,6 +57,7 @@ export declare class Normalizer {
56
57
  *
57
58
  * @param {NormalizeFlags} flags - A string of characters representing the normalization steps
58
59
  * @returns {NormalizerFn} - A function that normalizes a string based on the provided flags
60
+ * @throws {CmpStrInternalError} - Throws an error if the pipeline creation fails
59
61
  */
60
62
  private static getPipeline;
61
63
  /**
@@ -65,6 +67,7 @@ export declare class Normalizer {
65
67
  * @param {string | string[]} input - The string or array of strings to normalize
66
68
  * @param {NormalizeFlags} flags - A string of characters representing the normalization steps
67
69
  * @returns {string | string[]} - The normalized string(s)
70
+ * @throws {CmpStrInternalError} - Throws an error if the normalization process fails
68
71
  */
69
72
  static normalize(input: string | string[], flags: NormalizeFlags): string | string[];
70
73
  /**
@@ -75,6 +78,7 @@ export declare class Normalizer {
75
78
  * @param {string | string[]} input - The string or array of strings to normalize
76
79
  * @param {NormalizeFlags} flags - A string of characters representing the normalization steps
77
80
  * @returns {Promise< string | string[] >} - A promise that resolves to the normalized string(s)
81
+ * @throws {CmpStrInternalError} - Throws an error if the normalization process fails
78
82
  */
79
83
  static normalizeAsync(input: string | string[], flags: NormalizeFlags): Promise<string | string[]>;
80
84
  /**
@@ -12,7 +12,8 @@
12
12
  * It supports different types of buffers (Int32Array, number[], string[], Set, Map)
13
13
  * and allows for acquiring buffers of specific sizes while managing a max pool size.
14
14
  *
15
- * @module Utils/Pool
15
+ * @module Utils
16
+ * @name Pool
16
17
  * @author Paul Köhler (komed3)
17
18
  * @license MIT
18
19
  */
@@ -43,6 +44,7 @@ export declare class Pool {
43
44
  * @param {PoolType} type - The type of buffer to acquire (e.g., 'int32', 'number[]', 'map')
44
45
  * @param {number} size - The size of the buffer to acquire
45
46
  * @return {T} - The acquired buffer of the specified type
47
+ * @throws {CmpStrUsageError} - Throws an error if the pool type is unsupported
46
48
  */
47
49
  static acquire<T = any>(type: PoolType, size: number): T;
48
50
  /**
@@ -60,6 +62,7 @@ export declare class Pool {
60
62
  * @param {PoolType} type - The type of buffer to release
61
63
  * @param {T} buffer - The buffer to release
62
64
  * @param {number} size - The size of the buffer
65
+ * @throws {CmpStrUsageError} - Throws an error if the pool type is unsupported
63
66
  */
64
67
  static release<T = any>(type: PoolType, buffer: T, size: number): void;
65
68
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Profiler Utility
3
- * src/utils/profiler.ts
3
+ * src/utils/Profiler.ts
4
4
  *
5
5
  * @see https://en.wikipedia.org/wiki/Profiling_(computer_programming)
6
6
  *
@@ -12,7 +12,8 @@
12
12
  * The class is optimized for minimal overhead and can be used for fine-grained
13
13
  * performance profiling.
14
14
  *
15
- * @module Utils/Profiler
15
+ * @module Utils
16
+ * @name Profiler
16
17
  * @author Paul Köhler (komed3)
17
18
  * @license MIT
18
19
  */
@@ -8,7 +8,8 @@
8
8
  * It is designed to manage class extensions, ensuring that all registered
9
9
  * classes extend a specified base constructor.
10
10
  *
11
- * @module Utils/Registry
11
+ * @module Utils
12
+ * @name Registry
12
13
  * @author Paul Köhler (komed3)
13
14
  * @license MIT
14
15
  */
@@ -34,7 +35,7 @@ export declare const factory: Record<string, (cls: string, ...args: any[]) => In
34
35
  * @param {string} reg - The name of the registry
35
36
  * @param {RegistryConstructor< T >} ctor - The base constructor that all registered classes must extend
36
37
  * @returns {RegistryService< T >} - An object with methods to register, remove, check, get, and list classes
37
- * @throws {Error} If the registry already exists (overwriting is forbidden)
38
+ * @throws {Error} - If the registry already exists (overwriting is forbidden)
38
39
  */
39
40
  export declare function Registry<T>(reg: string, ctor: RegistryConstructor<T>): RegistryService<T>;
40
41
  /**
@@ -44,7 +45,7 @@ export declare function Registry<T>(reg: string, ctor: RegistryConstructor<T>):
44
45
  * @param {string} reg - The name of the registry
45
46
  * @param {T | string} cls - The class itself or name of the class to resolve
46
47
  * @returns {T | undefined} - The class constructor if found, otherwise undefined
47
- * @throws {ReferenceError} If the registry does not exist
48
+ * @throws {CmpStrNotFoundError} - If the registry or class does not exist
48
49
  */
49
50
  export declare function resolveCls<T extends RegistryConstructor<any>>(reg: string, cls: T | string): T;
50
51
  /**
@@ -55,6 +56,6 @@ export declare function resolveCls<T extends RegistryConstructor<any>>(reg: stri
55
56
  * @param {T | string} cls - The class itself or name of the class to instantiate
56
57
  * @param {...any} args - Arguments to pass to the class constructor
57
58
  * @returns {T} - An instance of the class
58
- * @throws {Error} If the class cannot be instantiated
59
+ * @throws {CmpStrInternalError} - If instantiation fails due to an internal error
59
60
  */
60
61
  export declare function createFromRegistry<T extends RegistryConstructor<any>>(reg: string, cls: T | string, ...args: any[]): InstanceType<T>;
@@ -13,7 +13,8 @@
13
13
  * - Integration with CmpStr comparison methods
14
14
  * - Optional "objects-only" output mode for minimal result structure
15
15
  *
16
- * @module Utils/StructuredData
16
+ * @module Utils
17
+ * @name StructuredData
17
18
  * @author Paul Köhler (komed3)
18
19
  * @license MIT
19
20
  */
@@ -79,7 +80,7 @@ export declare class StructuredData<T = any, R = MetricRaw> {
79
80
  *
80
81
  * @param {any} results - The raw metric results
81
82
  * @returns {IndexedResult< R >[]} - Normalized results with indices
82
- * @throws {TypeError} - If results format is unsupported
83
+ * @throws {CmpStrValidationError} - If the results format is unsupported
83
84
  */
84
85
  private normalizeResults;
85
86
  /**
@@ -120,6 +121,7 @@ export declare class StructuredData<T = any, R = MetricRaw> {
120
121
  * @param {string[]} extractedStrings - The extracted strings for index mapping
121
122
  * @param {StructuredDataOptions} [opt] - Additional options
122
123
  * @returns {StructuredDataBatchResult< T, R > | T[]} - The lookup results
124
+ * @throws {CmpStrUsageError} - If the lookup process fails
123
125
  */
124
126
  private performLookup;
125
127
  /**
@@ -129,6 +131,7 @@ export declare class StructuredData<T = any, R = MetricRaw> {
129
131
  * @param {string[]} extractedStrings - The extracted strings for index mapping
130
132
  * @param {StructuredDataOptions} [opt] - Additional options
131
133
  * @returns {Promise< StructuredDataBatchResult< T, R > | T[] >} - The async lookup results
134
+ * @throws {CmpStrUsageError} - If the async lookup process fails
132
135
  */
133
136
  private performLookupAsync;
134
137
  /**
@@ -9,7 +9,8 @@
9
9
  * efficiency and flexibility, it is suitable for linguistic research, readability
10
10
  * scoring, and text preprocessing tasks.
11
11
  *
12
- * @module Utils/TextAnalyzer
12
+ * @module Utils
13
+ * @name TextAnalyzer
13
14
  * @author Paul Köhler (komed3)
14
15
  * @license MIT
15
16
  */