cmpstr 3.1.0 → 3.2.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.
- package/LICENSE +2 -2
- package/README.md +43 -40
- package/dist/CmpStr.esm.js +946 -921
- 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 +935 -896
- 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 +26 -44
- package/dist/cjs/CmpStr.cjs.map +1 -1
- package/dist/cjs/CmpStrAsync.cjs +10 -5
- package/dist/cjs/CmpStrAsync.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/metric/Cosine.cjs +21 -21
- package/dist/cjs/metric/Cosine.cjs.map +1 -1
- package/dist/cjs/metric/DamerauLevenshtein.cjs +31 -29
- package/dist/cjs/metric/DamerauLevenshtein.cjs.map +1 -1
- package/dist/cjs/metric/DiceSorensen.cjs +16 -13
- package/dist/cjs/metric/DiceSorensen.cjs.map +1 -1
- package/dist/cjs/metric/Hamming.cjs +2 -2
- package/dist/cjs/metric/Hamming.cjs.map +1 -1
- package/dist/cjs/metric/Jaccard.cjs +16 -13
- package/dist/cjs/metric/Jaccard.cjs.map +1 -1
- package/dist/cjs/metric/JaroWinkler.cjs +45 -43
- package/dist/cjs/metric/JaroWinkler.cjs.map +1 -1
- package/dist/cjs/metric/LCS.cjs +21 -18
- package/dist/cjs/metric/LCS.cjs.map +1 -1
- package/dist/cjs/metric/Levenshtein.cjs +21 -18
- package/dist/cjs/metric/Levenshtein.cjs.map +1 -1
- package/dist/cjs/metric/Metric.cjs +18 -31
- package/dist/cjs/metric/Metric.cjs.map +1 -1
- package/dist/cjs/metric/NeedlemanWunsch.cjs +27 -24
- package/dist/cjs/metric/NeedlemanWunsch.cjs.map +1 -1
- package/dist/cjs/metric/{qGram.cjs → QGram.cjs} +18 -15
- package/dist/cjs/metric/QGram.cjs.map +1 -0
- package/dist/cjs/metric/SmithWaterman.cjs +27 -24
- package/dist/cjs/metric/SmithWaterman.cjs.map +1 -1
- package/dist/cjs/phonetic/Caverphone.cjs +5 -8
- 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 +6 -3
- package/dist/cjs/phonetic/Metaphone.cjs.map +1 -1
- package/dist/cjs/phonetic/Phonetic.cjs +23 -16
- 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 +3 -2
- package/dist/cjs/root.cjs.map +1 -1
- package/dist/cjs/utils/DeepMerge.cjs +73 -42
- package/dist/cjs/utils/DeepMerge.cjs.map +1 -1
- package/dist/cjs/utils/DiffChecker.cjs +33 -45
- package/dist/cjs/utils/DiffChecker.cjs.map +1 -1
- package/dist/cjs/utils/Filter.cjs +40 -46
- package/dist/cjs/utils/Filter.cjs.map +1 -1
- package/dist/cjs/utils/HashTable.cjs +23 -32
- package/dist/cjs/utils/HashTable.cjs.map +1 -1
- package/dist/cjs/utils/Normalizer.cjs +32 -21
- package/dist/cjs/utils/Normalizer.cjs.map +1 -1
- package/dist/cjs/utils/Pool.cjs +21 -26
- package/dist/cjs/utils/Pool.cjs.map +1 -1
- package/dist/cjs/utils/Profiler.cjs +40 -53
- package/dist/cjs/utils/Profiler.cjs.map +1 -1
- package/dist/cjs/utils/Registry.cjs +6 -4
- package/dist/cjs/utils/Registry.cjs.map +1 -1
- package/dist/cjs/utils/StructuredData.cjs +47 -37
- package/dist/cjs/utils/StructuredData.cjs.map +1 -1
- package/dist/cjs/utils/TextAnalyzer.cjs +76 -56
- package/dist/cjs/utils/TextAnalyzer.cjs.map +1 -1
- package/dist/esm/CmpStr.mjs +21 -44
- package/dist/esm/CmpStr.mjs.map +1 -1
- package/dist/esm/CmpStrAsync.mjs +5 -5
- package/dist/esm/CmpStrAsync.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/metric/Cosine.mjs +21 -21
- package/dist/esm/metric/Cosine.mjs.map +1 -1
- package/dist/esm/metric/DamerauLevenshtein.mjs +31 -29
- package/dist/esm/metric/DamerauLevenshtein.mjs.map +1 -1
- package/dist/esm/metric/DiceSorensen.mjs +16 -13
- package/dist/esm/metric/DiceSorensen.mjs.map +1 -1
- package/dist/esm/metric/Hamming.mjs +2 -2
- package/dist/esm/metric/Hamming.mjs.map +1 -1
- package/dist/esm/metric/Jaccard.mjs +16 -13
- package/dist/esm/metric/Jaccard.mjs.map +1 -1
- package/dist/esm/metric/JaroWinkler.mjs +45 -43
- package/dist/esm/metric/JaroWinkler.mjs.map +1 -1
- package/dist/esm/metric/LCS.mjs +21 -18
- package/dist/esm/metric/LCS.mjs.map +1 -1
- package/dist/esm/metric/Levenshtein.mjs +21 -18
- package/dist/esm/metric/Levenshtein.mjs.map +1 -1
- package/dist/esm/metric/Metric.mjs +19 -32
- package/dist/esm/metric/Metric.mjs.map +1 -1
- package/dist/esm/metric/NeedlemanWunsch.mjs +27 -24
- package/dist/esm/metric/NeedlemanWunsch.mjs.map +1 -1
- package/dist/esm/metric/QGram.mjs +38 -0
- package/dist/esm/metric/QGram.mjs.map +1 -0
- package/dist/esm/metric/SmithWaterman.mjs +27 -24
- package/dist/esm/metric/SmithWaterman.mjs.map +1 -1
- package/dist/esm/phonetic/Caverphone.mjs +5 -8
- 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 +6 -3
- package/dist/esm/phonetic/Metaphone.mjs.map +1 -1
- package/dist/esm/phonetic/Phonetic.mjs +24 -17
- 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 +3 -3
- package/dist/esm/utils/DeepMerge.mjs +73 -42
- package/dist/esm/utils/DeepMerge.mjs.map +1 -1
- package/dist/esm/utils/DiffChecker.mjs +33 -45
- package/dist/esm/utils/DiffChecker.mjs.map +1 -1
- package/dist/esm/utils/Filter.mjs +40 -46
- package/dist/esm/utils/Filter.mjs.map +1 -1
- package/dist/esm/utils/HashTable.mjs +23 -33
- package/dist/esm/utils/HashTable.mjs.map +1 -1
- package/dist/esm/utils/Normalizer.mjs +32 -21
- package/dist/esm/utils/Normalizer.mjs.map +1 -1
- package/dist/esm/utils/Pool.mjs +21 -26
- package/dist/esm/utils/Pool.mjs.map +1 -1
- package/dist/esm/utils/Profiler.mjs +40 -53
- package/dist/esm/utils/Profiler.mjs.map +1 -1
- package/dist/esm/utils/Registry.mjs +6 -4
- package/dist/esm/utils/Registry.mjs.map +1 -1
- package/dist/esm/utils/StructuredData.mjs +47 -37
- package/dist/esm/utils/StructuredData.mjs.map +1 -1
- package/dist/esm/utils/TextAnalyzer.mjs +76 -56
- package/dist/esm/utils/TextAnalyzer.mjs.map +1 -1
- package/dist/types/CmpStr.d.ts +56 -55
- package/dist/types/CmpStrAsync.d.ts +45 -45
- package/dist/types/index.d.ts +2 -2
- package/dist/types/metric/Cosine.d.ts +7 -5
- package/dist/types/metric/DamerauLevenshtein.d.ts +4 -2
- package/dist/types/metric/DiceSorensen.d.ts +5 -3
- package/dist/types/metric/Hamming.d.ts +4 -2
- package/dist/types/metric/Jaccard.d.ts +3 -1
- package/dist/types/metric/JaroWinkler.d.ts +4 -2
- package/dist/types/metric/LCS.d.ts +3 -1
- package/dist/types/metric/Levenshtein.d.ts +4 -2
- package/dist/types/metric/Metric.d.ts +23 -21
- package/dist/types/metric/NeedlemanWunsch.d.ts +4 -2
- package/dist/types/metric/{qGram.d.ts → QGram.d.ts} +5 -3
- package/dist/types/metric/SmithWaterman.d.ts +4 -2
- package/dist/types/metric/index.d.ts +2 -2
- package/dist/types/phonetic/Caverphone.d.ts +5 -2
- package/dist/types/phonetic/Cologne.d.ts +1 -0
- package/dist/types/phonetic/Metaphone.d.ts +3 -0
- package/dist/types/phonetic/Phonetic.d.ts +14 -10
- package/dist/types/phonetic/Soundex.d.ts +1 -0
- package/dist/types/phonetic/index.d.ts +1 -1
- package/dist/types/root.d.ts +7 -7
- package/dist/types/utils/DeepMerge.d.ts +4 -3
- package/dist/types/utils/DiffChecker.d.ts +9 -7
- package/dist/types/utils/Filter.d.ts +22 -8
- package/dist/types/utils/HashTable.d.ts +44 -10
- package/dist/types/utils/Normalizer.d.ts +13 -4
- package/dist/types/utils/Pool.d.ts +5 -3
- package/dist/types/utils/Profiler.d.ts +30 -15
- package/dist/types/utils/Registry.d.ts +11 -8
- package/dist/types/utils/StructuredData.d.ts +44 -32
- package/dist/types/utils/TextAnalyzer.d.ts +38 -14
- package/dist/types/utils/Types.d.ts +104 -14
- package/package.json +8 -3
- package/dist/cjs/metric/qGram.cjs.map +0 -1
- package/dist/esm/metric/qGram.mjs +0 -35
- package/dist/esm/metric/qGram.mjs.map +0 -1
package/dist/types/root.d.ts
CHANGED
|
@@ -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.
|
|
12
|
+
* @version 3.2.0
|
|
13
13
|
* @author Paul Köhler (komed3)
|
|
14
14
|
* @license MIT
|
|
15
15
|
*/
|
|
@@ -17,23 +17,23 @@ export * from './index';
|
|
|
17
17
|
/**
|
|
18
18
|
* Export utils to implement new metrics
|
|
19
19
|
*
|
|
20
|
-
* - MetricRegistry: Metric registry service for managing metric implementations.
|
|
21
20
|
* - Metric: Abstract class representing a generic string metric.
|
|
22
21
|
* - MetricCls: Type definition for a class constructor that extends the Metric class.
|
|
22
|
+
* - MetricRegistry: Metric registry service for managing metric implementations.
|
|
23
23
|
*/
|
|
24
|
-
export {
|
|
24
|
+
export { Metric, MetricCls, MetricRegistry } from './metric';
|
|
25
25
|
/**
|
|
26
26
|
* Export utils to implement new phonetic algorithms
|
|
27
27
|
*
|
|
28
|
-
* - PhoneticRegistry: Phonetic registry service for managing phonetic algorithm implementations.
|
|
29
|
-
* - PhoneticMappingRegistry: Registry for managing phonetic character mappings.
|
|
30
28
|
* - Phonetic: Abstract class representing a generic phonetic algorithm.
|
|
31
29
|
* - PhoneticCls: Type definition for a class constructor that extends the Phonetic class.
|
|
30
|
+
* - PhoneticMappingRegistry: Registry for managing phonetic character mappings.
|
|
31
|
+
* - PhoneticRegistry: Phonetic registry service for managing phonetic algorithm implementations.
|
|
32
32
|
*/
|
|
33
|
-
export {
|
|
33
|
+
export { Phonetic, PhoneticCls, PhoneticMappingRegistry, PhoneticRegistry } from './phonetic';
|
|
34
34
|
export * as DeepMerge from './utils/DeepMerge';
|
|
35
35
|
export { Filter } from './utils/Filter';
|
|
36
|
-
export { HashTable } from './utils/HashTable';
|
|
36
|
+
export { Hasher, HashTable } from './utils/HashTable';
|
|
37
37
|
export { Pool } from './utils/Pool';
|
|
38
38
|
export { Profiler } from './utils/Profiler';
|
|
39
39
|
export { StructuredData } from './utils/StructuredData';
|
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
* Deeply get a value from an object by a path string.
|
|
23
23
|
*
|
|
24
24
|
* @template T - The type of the object to get the value from
|
|
25
|
+
* @template R - The return type of the value
|
|
25
26
|
* @param {T} t - The object to get the value from
|
|
26
27
|
* @param {string} path - The path string, e.g. `a.b.c`
|
|
27
|
-
* @param {any}
|
|
28
|
-
* @returns {
|
|
28
|
+
* @param {any} fb - The default value to return if the path does not exist
|
|
29
|
+
* @returns {R | undefined} - The value at the specified path, otherwise the default value
|
|
29
30
|
*/
|
|
30
|
-
export declare function get<T extends Record<string, any>, R = any>(t: T, path: string,
|
|
31
|
+
export declare function get<T extends Record<string, any>, R = any>(t: T, path: string, fb?: R): R | undefined;
|
|
31
32
|
/**
|
|
32
33
|
* Check if a path exists in an object.
|
|
33
34
|
*
|
|
@@ -24,17 +24,20 @@
|
|
|
24
24
|
* @author Paul Köhler (komed3)
|
|
25
25
|
* @license MIT
|
|
26
26
|
*/
|
|
27
|
-
import type {
|
|
27
|
+
import type { DiffGroup, DiffLine, DiffOptions } from './Types';
|
|
28
28
|
/**
|
|
29
29
|
* The DiffChecker class provides methods to compare two texts and generate
|
|
30
30
|
* structured diffs, grouped diffs, and unified diff outputs.
|
|
31
31
|
*/
|
|
32
32
|
export declare class DiffChecker {
|
|
33
|
+
/** Original input texts and options */
|
|
33
34
|
private readonly a;
|
|
34
35
|
private readonly b;
|
|
35
36
|
private readonly options;
|
|
37
|
+
/** Computed diff entries and groups */
|
|
36
38
|
private entries;
|
|
37
39
|
private grouped;
|
|
40
|
+
/** Flag to indicate if the diff has already been computed */
|
|
38
41
|
private diffRun;
|
|
39
42
|
/**
|
|
40
43
|
* Constructs a new DiffChecker instance for comparing two texts.
|
|
@@ -45,8 +48,7 @@ export declare class DiffChecker {
|
|
|
45
48
|
*/
|
|
46
49
|
constructor(a: string, b: string, opt?: DiffOptions);
|
|
47
50
|
/**
|
|
48
|
-
* Splits both input texts into arrays of lines and returns them
|
|
49
|
-
* with the maximum line count.
|
|
51
|
+
* Splits both input texts into arrays of lines and returns them with the maximum line count.
|
|
50
52
|
*
|
|
51
53
|
* @returns { linesA: string[], linesB: string[], maxLen: number }
|
|
52
54
|
*/
|
|
@@ -115,23 +117,23 @@ export declare class DiffChecker {
|
|
|
115
117
|
*
|
|
116
118
|
* @returns {DiffLine[]} - Array of line-level diffs
|
|
117
119
|
*/
|
|
118
|
-
getStructuredDiff()
|
|
120
|
+
getStructuredDiff: () => DiffLine[];
|
|
119
121
|
/**
|
|
120
122
|
* Returns the grouped diff as an array of DiffGroup objects.
|
|
121
123
|
*
|
|
122
124
|
* @returns {DiffGroup[]} - Array of grouped diffs
|
|
123
125
|
*/
|
|
124
|
-
getGroupedDiff()
|
|
126
|
+
getGroupedDiff: () => DiffGroup[];
|
|
125
127
|
/**
|
|
126
128
|
* Returns the unified diff as a plain ASCII string.
|
|
127
129
|
*
|
|
128
130
|
* @returns {string} - Unified diff (ASCII)
|
|
129
131
|
*/
|
|
130
|
-
getASCIIDiff()
|
|
132
|
+
getASCIIDiff: () => string;
|
|
131
133
|
/**
|
|
132
134
|
* Returns the unified diff as a CLI-colored string.
|
|
133
135
|
*
|
|
134
136
|
* @returns {string} - Unified diff (CLI colors)
|
|
135
137
|
*/
|
|
136
|
-
getCLIDiff()
|
|
138
|
+
getCLIDiff: () => string;
|
|
137
139
|
}
|
|
@@ -18,17 +18,30 @@ import type { FilterFn, FilterOptions } from './Types';
|
|
|
18
18
|
export declare class Filter {
|
|
19
19
|
/**
|
|
20
20
|
* A static map to hold all filters.
|
|
21
|
-
* The key is the hook name, and the value is an
|
|
21
|
+
* The key is the hook name, and the value is an Map of FilterEntry objects.
|
|
22
22
|
*/
|
|
23
23
|
private static filters;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* A map that holds the pipeline of filters to be applied.
|
|
26
|
+
* The key is the hook name, and the value is the compiled function.
|
|
27
|
+
*/
|
|
28
|
+
private static pipeline;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the compiled filter function for a given hook.
|
|
31
|
+
* If the function is not cached, it compiles it from the active filters.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} hook - The name of the hook
|
|
34
|
+
* @returns {FilterFn} - The compiled filter function for the hook
|
|
35
|
+
*/
|
|
36
|
+
private static getPipeline;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a filter exists for a given hook and id.
|
|
26
39
|
*
|
|
27
40
|
* @param {string} hook - The name of the hook
|
|
28
41
|
* @param {string} id - The id of the filter
|
|
29
|
-
* @returns {
|
|
42
|
+
* @returns {boolean} - Returns true if the filter exists, false otherwise
|
|
30
43
|
*/
|
|
31
|
-
|
|
44
|
+
static has(hook: string, id: string): boolean;
|
|
32
45
|
/**
|
|
33
46
|
* Adds a filter to the specified hook.
|
|
34
47
|
*
|
|
@@ -75,8 +88,8 @@ export declare class Filter {
|
|
|
75
88
|
* Applies all active filters for a given hook to the input string(s).
|
|
76
89
|
*
|
|
77
90
|
* @param {string} hook - The name of the hook
|
|
78
|
-
* @param {string|string[]} input - The input string(s) to be filtered
|
|
79
|
-
* @returns {string|string[]} - The filtered string(s)
|
|
91
|
+
* @param {string | string[]} input - The input string(s) to be filtered
|
|
92
|
+
* @returns {string | string[]} - The filtered string(s)
|
|
80
93
|
*/
|
|
81
94
|
static apply(hook: string, input: string | string[]): string | string[];
|
|
82
95
|
/**
|
|
@@ -84,12 +97,13 @@ export declare class Filter {
|
|
|
84
97
|
* Each filter function may return a Promise or a plain string; all are awaited in order.
|
|
85
98
|
*
|
|
86
99
|
* @param {string} hook - The name of the hook
|
|
87
|
-
* @param {string|string[]} input - The input string(s) to be filtered
|
|
88
|
-
* @returns {Promise<string|string[]>} - The filtered string(s)
|
|
100
|
+
* @param {string | string[]} input - The input string(s) to be filtered
|
|
101
|
+
* @returns {Promise< string | string[] >} - The filtered string(s)
|
|
89
102
|
*/
|
|
90
103
|
static applyAsync(hook: string, input: string | string[]): Promise<string | string[]>;
|
|
91
104
|
/**
|
|
92
105
|
* Clears all filters or filters for a specific hook.
|
|
106
|
+
* If no hook is provided, clear all filters
|
|
93
107
|
*
|
|
94
108
|
* @param {string} [hook] - Optional name of the hook to clear filters for
|
|
95
109
|
*/
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
* src/utils/HashTable.ts
|
|
4
4
|
*
|
|
5
5
|
* @see https://en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function
|
|
6
|
+
* @see https://en.wikipedia.org/wiki/MurmurHash
|
|
6
7
|
* @see https://en.wikipedia.org/wiki/Hash_table
|
|
7
8
|
*
|
|
8
|
-
* This module implements an instantiable hash table/cache using
|
|
9
|
+
* This module implements an instantiable hash table/cache using a modified FNV-1a hash
|
|
10
|
+
* algorithm, optimized for speed and low collision rates.
|
|
11
|
+
*
|
|
9
12
|
* It allows for multiple independent caches (e.g. for metrics, normalization, etc.) with
|
|
10
|
-
* type safety and high performance.
|
|
11
|
-
* static utility class to avoid code duplication and memory overhead.
|
|
13
|
+
* type safety and high performance.
|
|
12
14
|
*
|
|
13
15
|
* The key() method supports any number of string arguments, enabling flexible cache keys
|
|
14
16
|
* for different use cases (e.g. normalization, metrics, etc.).
|
|
@@ -17,6 +19,26 @@
|
|
|
17
19
|
* @author Paul Köhler (komed3)
|
|
18
20
|
* @license MIT
|
|
19
21
|
*/
|
|
22
|
+
/**
|
|
23
|
+
* Hasher Utility
|
|
24
|
+
* Static class for modified FNV-1a hash algorithm implementation.
|
|
25
|
+
*/
|
|
26
|
+
export declare class Hasher {
|
|
27
|
+
/** Constants for the hash algorithm */
|
|
28
|
+
private static readonly FNV_PRIME;
|
|
29
|
+
private static readonly HASH_OFFSET;
|
|
30
|
+
/**
|
|
31
|
+
* Computes a hash value for a given string using the FNV-1a algorithm.
|
|
32
|
+
*
|
|
33
|
+
* Modifications:
|
|
34
|
+
* - Processes 4 characters at a time (chunks)
|
|
35
|
+
* - Using MurmurHash3 finalizer
|
|
36
|
+
*
|
|
37
|
+
* @param {string} str - The string to hash
|
|
38
|
+
* @return {number} - The computed hash value as an unsigned 32-bit integer
|
|
39
|
+
*/
|
|
40
|
+
static fastFNV1a(str: string): number;
|
|
41
|
+
}
|
|
20
42
|
/**
|
|
21
43
|
* HashTable class implements an instantiable hash table/cache.
|
|
22
44
|
* Allows for multiple independent caches with type safety and high performance.
|
|
@@ -25,7 +47,10 @@
|
|
|
25
47
|
* @template T - The type of value to be stored in the hash table (e.g. MetricCompute, string, …)
|
|
26
48
|
*/
|
|
27
49
|
export declare class HashTable<K extends string, T> {
|
|
50
|
+
private readonly LRU;
|
|
51
|
+
/** The max. length of a string to hash, which is set to 2048 characters */
|
|
28
52
|
private static readonly MAX_LEN;
|
|
53
|
+
/** The max. size of the hash table, which is set to 10,000 */
|
|
29
54
|
private static readonly TABLE_SIZE;
|
|
30
55
|
/**
|
|
31
56
|
* The internal map to store entries.
|
|
@@ -33,14 +58,21 @@ export declare class HashTable<K extends string, T> {
|
|
|
33
58
|
* The value is of type T.
|
|
34
59
|
*/
|
|
35
60
|
private table;
|
|
61
|
+
/**
|
|
62
|
+
* Creates an instance of HashTable.
|
|
63
|
+
*
|
|
64
|
+
* @param {boolean} [LRU=true] - Whether to use Least Recently Used (LRU) eviction policy
|
|
65
|
+
*/
|
|
66
|
+
constructor(LRU?: boolean);
|
|
36
67
|
/**
|
|
37
68
|
* Generates a unique hash key for any number of string arguments.
|
|
69
|
+
* Return false if any string exceeds the maximum length.
|
|
38
70
|
* The key is in the format "label-H1-H2-H3-..."
|
|
39
71
|
*
|
|
40
72
|
* @param {K} label - Label for this key (e.g. metric name, normalization flags, …)
|
|
41
73
|
* @param {string[]} strs - Array of strings to hash (e.g. input, params, …)
|
|
42
74
|
* @param {boolean} [sorted=false] - Whether to sort the hashes before creating the key
|
|
43
|
-
* @returns {string|false} - A unique hash key or false if any string is too long
|
|
75
|
+
* @returns {string | false} - A unique hash key or false if any string is too long
|
|
44
76
|
*/
|
|
45
77
|
key(label: K, strs: string[], sorted?: boolean): string | false;
|
|
46
78
|
/**
|
|
@@ -49,16 +81,17 @@ export declare class HashTable<K extends string, T> {
|
|
|
49
81
|
* @param {string} key - The key to check
|
|
50
82
|
* @returns {boolean} - True if the key exists, false otherwise
|
|
51
83
|
*/
|
|
52
|
-
has(key: string)
|
|
84
|
+
has: (key: string) => boolean;
|
|
53
85
|
/**
|
|
54
86
|
* Retrieves the entry from the hash table by its key.
|
|
55
87
|
*
|
|
56
88
|
* @param {string} key - The key to look up
|
|
57
|
-
* @returns {T|undefined} - The entry if found, undefined otherwise
|
|
89
|
+
* @returns {T | undefined} - The entry if found, undefined otherwise
|
|
58
90
|
*/
|
|
59
|
-
get(key: string)
|
|
91
|
+
get: (key: string) => T | undefined;
|
|
60
92
|
/**
|
|
61
93
|
* Adds an entry to the hash table.
|
|
94
|
+
* If the table is full, it evicts the least recently used entry (if LRU is enabled).
|
|
62
95
|
*
|
|
63
96
|
* @param {string} key - The hashed key for the entry
|
|
64
97
|
* @param {T} entry - The entry itself to add
|
|
@@ -70,17 +103,18 @@ export declare class HashTable<K extends string, T> {
|
|
|
70
103
|
* Deletes an entry from the hash table by its key.
|
|
71
104
|
*
|
|
72
105
|
* @param {string} key - The key of the entry to delete
|
|
106
|
+
* @returns {boolean} - True if the entry was deleted, false if the key was not found
|
|
73
107
|
*/
|
|
74
|
-
delete(key: string)
|
|
108
|
+
delete: (key: string) => boolean;
|
|
75
109
|
/**
|
|
76
110
|
* Clears the hash table.
|
|
77
111
|
* This method removes all entries from the hash table.
|
|
78
112
|
*/
|
|
79
|
-
clear()
|
|
113
|
+
clear: () => void;
|
|
80
114
|
/**
|
|
81
115
|
* Returns the current size of the hash table.
|
|
82
116
|
*
|
|
83
117
|
* @returns {number} - The number of entries in the hash table
|
|
84
118
|
*/
|
|
85
|
-
size()
|
|
119
|
+
size: () => number;
|
|
86
120
|
}
|
|
@@ -41,6 +41,15 @@ export declare class Normalizer {
|
|
|
41
41
|
* This helps avoid recomputing normalization for the same input and flags.
|
|
42
42
|
*/
|
|
43
43
|
private static cache;
|
|
44
|
+
/** Regular expressions used in normalization steps */
|
|
45
|
+
private static readonly REGEX;
|
|
46
|
+
/**
|
|
47
|
+
* Returns a canonical version of the flags by removing duplicates and sorting them.
|
|
48
|
+
*
|
|
49
|
+
* @param {NormalizeFlags} flags - The normalization flags
|
|
50
|
+
* @returns {NormalizeFlags} - The canonicalized flags
|
|
51
|
+
*/
|
|
52
|
+
private static canonicalFlags;
|
|
44
53
|
/**
|
|
45
54
|
* Returns a normalization function based on the provided flags.
|
|
46
55
|
* The flags are a string of characters that define the normalization steps.
|
|
@@ -53,9 +62,9 @@ export declare class Normalizer {
|
|
|
53
62
|
* Normalizes the input string or array of strings based on the provided flags.
|
|
54
63
|
* The flags are a string of characters that define the normalization steps.
|
|
55
64
|
*
|
|
56
|
-
* @param {string|string[]} input - The string or array of strings to normalize
|
|
65
|
+
* @param {string | string[]} input - The string or array of strings to normalize
|
|
57
66
|
* @param {NormalizeFlags} flags - A string of characters representing the normalization steps
|
|
58
|
-
* @returns {string|string[]} - The normalized string(s)
|
|
67
|
+
* @returns {string | string[]} - The normalized string(s)
|
|
59
68
|
*/
|
|
60
69
|
static normalize(input: string | string[], flags: NormalizeFlags): string | string[];
|
|
61
70
|
/**
|
|
@@ -63,9 +72,9 @@ export declare class Normalizer {
|
|
|
63
72
|
* provided flags. This method is useful for handling large inputs or when
|
|
64
73
|
* normalization needs to be done in a non-blocking way.
|
|
65
74
|
*
|
|
66
|
-
* @param {string|string[]} input - The string or array of strings to normalize
|
|
75
|
+
* @param {string | string[]} input - The string or array of strings to normalize
|
|
67
76
|
* @param {NormalizeFlags} flags - A string of characters representing the normalization steps
|
|
68
|
-
* @returns {Promise<string|string[]>} - A promise that resolves to the normalized string(s)
|
|
77
|
+
* @returns {Promise< string | string[] >} - A promise that resolves to the normalized string(s)
|
|
69
78
|
*/
|
|
70
79
|
static normalizeAsync(input: string | string[], flags: NormalizeFlags): Promise<string | string[]>;
|
|
71
80
|
/**
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* By reusing pre-allocated typed arrays, it reduces memory allocations and garbage
|
|
10
10
|
* collection overhead, especially for repeated or batch computations.
|
|
11
11
|
*
|
|
12
|
-
* It supports different types of buffers (
|
|
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
15
|
* @module Utils/Pool
|
|
@@ -20,11 +20,13 @@ import type { PoolType } from './Types';
|
|
|
20
20
|
/**
|
|
21
21
|
* The Pool class provides a buffer pool for dynamic programming algorithms.
|
|
22
22
|
*
|
|
23
|
-
* It allows for efficient reuse of buffers (
|
|
23
|
+
* It allows for efficient reuse of buffers (Int32Array, number[], Set, Map)
|
|
24
24
|
* to reduce memory allocations and garbage collection overhead.
|
|
25
25
|
*/
|
|
26
26
|
export declare class Pool {
|
|
27
|
+
/** Pool Types */
|
|
27
28
|
private static readonly CONFIG;
|
|
29
|
+
/** Pool Rings for each type */
|
|
28
30
|
private static readonly POOLS;
|
|
29
31
|
/**
|
|
30
32
|
* Allocates a new buffer of the specified type and size.
|
|
@@ -38,7 +40,7 @@ export declare class Pool {
|
|
|
38
40
|
* Acquires a buffer of the specified type and size from the pool.
|
|
39
41
|
* If no suitable buffer is available, it allocates a new one.
|
|
40
42
|
*
|
|
41
|
-
* @param {PoolType} type - The type of buffer to acquire (e.g., '
|
|
43
|
+
* @param {PoolType} type - The type of buffer to acquire (e.g., 'int32', 'number[]', 'map')
|
|
42
44
|
* @param {number} size - The size of the buffer to acquire
|
|
43
45
|
* @return {T} - The acquired buffer of the specified type
|
|
44
46
|
*/
|
|
@@ -21,19 +21,26 @@ import type { ProfilerEntry, ProfilerService } from './Types';
|
|
|
21
21
|
* Profiler class for measuring execution time and memory usage of functions.
|
|
22
22
|
*/
|
|
23
23
|
export declare class Profiler {
|
|
24
|
+
private active;
|
|
25
|
+
/** Environment detection */
|
|
24
26
|
private static ENV;
|
|
27
|
+
/** Singleton instance */
|
|
25
28
|
private static instance;
|
|
29
|
+
/** Pre-computed functions for time and memory retrieval */
|
|
30
|
+
private nowFn;
|
|
31
|
+
private memFn;
|
|
32
|
+
/** Store for profiler entries */
|
|
26
33
|
private store;
|
|
34
|
+
/** Total time and memory consumption */
|
|
27
35
|
private totalTime;
|
|
28
36
|
private totalMem;
|
|
29
|
-
private active;
|
|
30
37
|
/**
|
|
31
38
|
* Sets the environment based on the available global objects.
|
|
32
39
|
* Detects if running in Node.js or browser and sets the ENV property accordingly.
|
|
33
40
|
*/
|
|
34
41
|
protected static detectEnv(): void;
|
|
35
42
|
/**
|
|
36
|
-
* Returns the singleton instance of the
|
|
43
|
+
* Returns the singleton instance of the Profiler class.
|
|
37
44
|
* If the instance does not exist, it creates a new one.
|
|
38
45
|
*
|
|
39
46
|
* @param {boolean} [enable=false] - Optional parameter to enable the profiler upon instantiation
|
|
@@ -44,7 +51,7 @@ export declare class Profiler {
|
|
|
44
51
|
* Private constructor to enforce singleton pattern.
|
|
45
52
|
* Initializes the store for profiler entries.
|
|
46
53
|
*
|
|
47
|
-
* @param {boolean} [
|
|
54
|
+
* @param {boolean} [active=false] - Optional parameter to enable the profiler
|
|
48
55
|
*/
|
|
49
56
|
private constructor();
|
|
50
57
|
/**
|
|
@@ -65,16 +72,24 @@ export declare class Profiler {
|
|
|
65
72
|
* @returns {number} - Current memory usage in bytes
|
|
66
73
|
*/
|
|
67
74
|
private mem;
|
|
75
|
+
/**
|
|
76
|
+
* Profiles a synchronous function by measuring its execution time and memory usage.
|
|
77
|
+
*
|
|
78
|
+
* @param {() => T} fn - Function to be executed and profiled
|
|
79
|
+
* @param {Record< string, any >} meta - Metadata to be associated with the profiling entry
|
|
80
|
+
* @returns {T} - The result of the executed function
|
|
81
|
+
*/
|
|
82
|
+
private profile;
|
|
68
83
|
/**
|
|
69
84
|
* Enables the profiler.
|
|
70
85
|
* Sets the active state to true, allowing profiling to occur.
|
|
71
86
|
*/
|
|
72
|
-
enable()
|
|
87
|
+
enable: () => void;
|
|
73
88
|
/**
|
|
74
89
|
* Disables the profiler.
|
|
75
90
|
* Sets the active state to false, preventing further profiling.
|
|
76
91
|
*/
|
|
77
|
-
disable()
|
|
92
|
+
disable: () => void;
|
|
78
93
|
/**
|
|
79
94
|
* Resets the profiler by clearing the store, total time and memory consumption.
|
|
80
95
|
* This method is useful for starting a new profiling session.
|
|
@@ -85,7 +100,7 @@ export declare class Profiler {
|
|
|
85
100
|
* If the profiler is not active, it simply executes the function without profiling.
|
|
86
101
|
*
|
|
87
102
|
* @param {() => T} fn - Function to be executed and profiled
|
|
88
|
-
* @param {Record<string, any>} meta - Metadata to be associated with the profiling entry
|
|
103
|
+
* @param {Record< string, any >} meta - Metadata to be associated with the profiling entry
|
|
89
104
|
* @returns {T} - The result of the executed function
|
|
90
105
|
*/
|
|
91
106
|
run<T>(fn: () => T, meta?: Record<string, any>): T;
|
|
@@ -93,29 +108,29 @@ export declare class Profiler {
|
|
|
93
108
|
* Runs an asynchronous function and profiles its execution time and memory usage.
|
|
94
109
|
* If the profiler is not active, it simply executes the function without profiling.
|
|
95
110
|
*
|
|
96
|
-
* @param {() => Promise<T>} fn - Asynchronous function to be executed and profiled
|
|
97
|
-
* @param {Record<string, any>} meta - Metadata to be associated with the profiling entry
|
|
98
|
-
* @returns {Promise<T>} - A promise that resolves to the result of the executed function
|
|
111
|
+
* @param {() => Promise< T >} fn - Asynchronous function to be executed and profiled
|
|
112
|
+
* @param {Record< string, any >} meta - Metadata to be associated with the profiling entry
|
|
113
|
+
* @returns {Promise< T >} - A promise that resolves to the result of the executed function
|
|
99
114
|
*/
|
|
100
115
|
runAsync<T>(fn: () => Promise<T>, meta?: Record<string, any>): Promise<T>;
|
|
101
116
|
/**
|
|
102
117
|
* Retrieves all profiler entries stored in the profiler.
|
|
103
118
|
*
|
|
104
|
-
* @returns {ProfilerEntry<any>[]} - An array of profiler entries
|
|
119
|
+
* @returns {ProfilerEntry< any >[]} - An array of profiler entries
|
|
105
120
|
*/
|
|
106
|
-
getAll()
|
|
121
|
+
getAll: () => ProfilerEntry<any>[];
|
|
107
122
|
/**
|
|
108
123
|
* Retrieves the last profiler entry stored in the profiler.
|
|
109
124
|
*
|
|
110
|
-
* @returns {ProfilerEntry<any> | undefined} - The last profiler entry or undefined if no entries exist
|
|
125
|
+
* @returns {ProfilerEntry< any > | undefined} - The last profiler entry or undefined if no entries exist
|
|
111
126
|
*/
|
|
112
|
-
getLast()
|
|
127
|
+
getLast: () => ProfilerEntry<any> | undefined;
|
|
113
128
|
/**
|
|
114
129
|
* Retrieves the total time and memory consumption recorded by the profiler.
|
|
115
130
|
*
|
|
116
131
|
* @returns {{ time: number, mem: number }} - An object containing total time and memory usage
|
|
117
132
|
*/
|
|
118
|
-
getTotal()
|
|
133
|
+
getTotal: () => {
|
|
119
134
|
time: number;
|
|
120
135
|
mem: number;
|
|
121
136
|
};
|
|
@@ -123,7 +138,7 @@ export declare class Profiler {
|
|
|
123
138
|
* Returns the services provided by the Profiler class.
|
|
124
139
|
* This allows for easy access to the profiler's methods.
|
|
125
140
|
*
|
|
126
|
-
* @returns {ProfilerService<any>} - An object containing methods to control the profiler
|
|
141
|
+
* @returns {ProfilerService< any >} - An object containing methods to control the profiler
|
|
127
142
|
*/
|
|
128
143
|
services: ProfilerService<any>;
|
|
129
144
|
}
|
|
@@ -12,44 +12,47 @@
|
|
|
12
12
|
* @author Paul Köhler (komed3)
|
|
13
13
|
* @license MIT
|
|
14
14
|
*/
|
|
15
|
-
import type {
|
|
15
|
+
import type { RegistryConstructor, RegistryService } from './Types';
|
|
16
16
|
/**
|
|
17
17
|
* Global registry object to hold multiple registries.
|
|
18
18
|
* Each registry is keyed by a string identifier.
|
|
19
19
|
*
|
|
20
|
-
* @type {Record<string, RegistryService<any
|
|
20
|
+
* @type {Record< string, RegistryService< any > >}
|
|
21
21
|
*/
|
|
22
22
|
export declare const registry: Record<string, RegistryService<any>>;
|
|
23
23
|
/**
|
|
24
24
|
* Factory object to hold factory functions for creating instances.
|
|
25
25
|
* This is used to create instances of registered classes.
|
|
26
26
|
*
|
|
27
|
-
* @type {Record<string, ( cls: string, ...args: any[] ) => InstanceType<any
|
|
27
|
+
* @type {Record< string, ( cls: string, ...args: any[] ) => InstanceType< any > >}
|
|
28
28
|
*/
|
|
29
29
|
export declare const factory: Record<string, (cls: string, ...args: any[]) => InstanceType<any>>;
|
|
30
30
|
/**
|
|
31
31
|
* Registry function to create a service for managing class constructors.
|
|
32
32
|
*
|
|
33
|
+
* @template T - The basic type of all registry class constructors
|
|
33
34
|
* @param {string} reg - The name of the registry
|
|
34
|
-
* @param {RegistryConstructor<T>} ctor - The base constructor that all registered classes must extend
|
|
35
|
-
* @returns {RegistryService<T>} - An object with methods to register, remove, check, get, and list classes
|
|
35
|
+
* @param {RegistryConstructor< T >} ctor - The base constructor that all registered classes must extend
|
|
36
|
+
* @returns {RegistryService< T >} - An object with methods to register, remove, check, get, and list classes
|
|
36
37
|
* @throws {Error} If the registry already exists (overwriting is forbidden)
|
|
37
38
|
*/
|
|
38
39
|
export declare function Registry<T>(reg: string, ctor: RegistryConstructor<T>): RegistryService<T>;
|
|
39
40
|
/**
|
|
40
41
|
* Resolve a class constructor from a specific registry.
|
|
41
42
|
*
|
|
43
|
+
* @template T - Type of the registry class constructor
|
|
42
44
|
* @param {string} reg - The name of the registry
|
|
43
|
-
* @param {T|string} cls - The class itself or name of the class to resolve
|
|
44
|
-
* @returns {T|undefined} - The class constructor if found, otherwise undefined
|
|
45
|
+
* @param {T | string} cls - The class itself or name of the class to resolve
|
|
46
|
+
* @returns {T | undefined} - The class constructor if found, otherwise undefined
|
|
45
47
|
* @throws {ReferenceError} If the registry does not exist
|
|
46
48
|
*/
|
|
47
49
|
export declare function resolveCls<T extends RegistryConstructor<any>>(reg: string, cls: T | string): T;
|
|
48
50
|
/**
|
|
49
51
|
* Create an instance of a class from a specific registry.
|
|
50
52
|
*
|
|
53
|
+
* @template T - Type of the registry class constructor
|
|
51
54
|
* @param {string} reg - The name of the registry
|
|
52
|
-
* @param {T|string} cls - The class itself or name of the class to instantiate
|
|
55
|
+
* @param {T | string} cls - The class itself or name of the class to instantiate
|
|
53
56
|
* @param {...any} args - Arguments to pass to the class constructor
|
|
54
57
|
* @returns {T} - An instance of the class
|
|
55
58
|
* @throws {Error} If the class cannot be instantiated
|