cmpstr 2.0.2 → 3.0.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 +21 -21
- package/README.md +75 -499
- package/dist/CmpStr.esm.js +4863 -0
- package/dist/CmpStr.esm.js.map +1 -0
- package/dist/CmpStr.esm.min.js +8 -0
- package/dist/CmpStr.esm.min.js.map +1 -0
- package/dist/CmpStr.umd.js +4875 -0
- package/dist/CmpStr.umd.js.map +1 -0
- package/dist/CmpStr.umd.min.js +8 -0
- package/dist/CmpStr.umd.min.js.map +1 -0
- package/dist/cjs/CmpStr.js +663 -0
- package/dist/cjs/CmpStr.js.map +1 -0
- package/dist/cjs/CmpStrAsync.js +336 -0
- package/dist/cjs/CmpStrAsync.js.map +1 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/metric/Cosine.js +101 -0
- package/dist/cjs/metric/Cosine.js.map +1 -0
- package/dist/cjs/metric/DamerauLevenshtein.js +110 -0
- package/dist/cjs/metric/DamerauLevenshtein.js.map +1 -0
- package/dist/cjs/metric/DiceSorensen.js +91 -0
- package/dist/cjs/metric/DiceSorensen.js.map +1 -0
- package/dist/cjs/metric/Hamming.js +82 -0
- package/dist/cjs/metric/Hamming.js.map +1 -0
- package/dist/cjs/metric/Jaccard.js +76 -0
- package/dist/cjs/metric/Jaccard.js.map +1 -0
- package/dist/cjs/metric/JaroWinkler.js +114 -0
- package/dist/cjs/metric/JaroWinkler.js.map +1 -0
- package/dist/cjs/metric/LCS.js +89 -0
- package/dist/cjs/metric/LCS.js.map +1 -0
- package/dist/cjs/metric/Levenshtein.js +94 -0
- package/dist/cjs/metric/Levenshtein.js.map +1 -0
- package/dist/cjs/metric/Metric.js +445 -0
- package/dist/cjs/metric/Metric.js.map +1 -0
- package/dist/cjs/metric/NeedlemanWunsch.js +95 -0
- package/dist/cjs/metric/NeedlemanWunsch.js.map +1 -0
- package/dist/cjs/metric/SmithWaterman.js +98 -0
- package/dist/cjs/metric/SmithWaterman.js.map +1 -0
- package/dist/cjs/metric/qGram.js +91 -0
- package/dist/cjs/metric/qGram.js.map +1 -0
- package/dist/cjs/phonetic/Cologne.js +112 -0
- package/dist/cjs/phonetic/Cologne.js.map +1 -0
- package/dist/cjs/phonetic/Metaphone.js +172 -0
- package/dist/cjs/phonetic/Metaphone.js.map +1 -0
- package/dist/cjs/phonetic/Phonetic.js +413 -0
- package/dist/cjs/phonetic/Phonetic.js.map +1 -0
- package/dist/cjs/phonetic/Soundex.js +135 -0
- package/dist/cjs/phonetic/Soundex.js.map +1 -0
- package/dist/cjs/utils/DeepMerge.js +144 -0
- package/dist/cjs/utils/DeepMerge.js.map +1 -0
- package/dist/cjs/utils/DiffChecker.js +500 -0
- package/dist/cjs/utils/DiffChecker.js.map +1 -0
- package/dist/cjs/utils/Filter.js +189 -0
- package/dist/cjs/utils/Filter.js.map +1 -0
- package/dist/cjs/utils/HashTable.js +175 -0
- package/dist/cjs/utils/HashTable.js.map +1 -0
- package/dist/cjs/utils/Normalizer.js +144 -0
- package/dist/cjs/utils/Normalizer.js.map +1 -0
- package/dist/cjs/utils/Pool.js +196 -0
- package/dist/cjs/utils/Pool.js.map +1 -0
- package/dist/cjs/utils/Profiler.js +229 -0
- package/dist/cjs/utils/Profiler.js.map +1 -0
- package/dist/cjs/utils/Registry.js +148 -0
- package/dist/cjs/utils/Registry.js.map +1 -0
- package/dist/cjs/utils/TextAnalyzer.js +358 -0
- package/dist/cjs/utils/TextAnalyzer.js.map +1 -0
- package/dist/esm/CmpStr.js +662 -0
- package/dist/esm/CmpStr.js.map +1 -0
- package/dist/esm/CmpStrAsync.js +331 -0
- package/dist/esm/CmpStrAsync.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/metric/Cosine.js +99 -0
- package/dist/esm/metric/Cosine.js.map +1 -0
- package/dist/esm/metric/DamerauLevenshtein.js +108 -0
- package/dist/esm/metric/DamerauLevenshtein.js.map +1 -0
- package/dist/esm/metric/DiceSorensen.js +89 -0
- package/dist/esm/metric/DiceSorensen.js.map +1 -0
- package/dist/esm/metric/Hamming.js +77 -0
- package/dist/esm/metric/Hamming.js.map +1 -0
- package/dist/esm/metric/Jaccard.js +74 -0
- package/dist/esm/metric/Jaccard.js.map +1 -0
- package/dist/esm/metric/JaroWinkler.js +112 -0
- package/dist/esm/metric/JaroWinkler.js.map +1 -0
- package/dist/esm/metric/LCS.js +87 -0
- package/dist/esm/metric/LCS.js.map +1 -0
- package/dist/esm/metric/Levenshtein.js +92 -0
- package/dist/esm/metric/Levenshtein.js.map +1 -0
- package/dist/esm/metric/Metric.js +442 -0
- package/dist/esm/metric/Metric.js.map +1 -0
- package/dist/esm/metric/NeedlemanWunsch.js +93 -0
- package/dist/esm/metric/NeedlemanWunsch.js.map +1 -0
- package/dist/esm/metric/SmithWaterman.js +96 -0
- package/dist/esm/metric/SmithWaterman.js.map +1 -0
- package/dist/esm/metric/qGram.js +89 -0
- package/dist/esm/metric/qGram.js.map +1 -0
- package/dist/esm/phonetic/Cologne.js +114 -0
- package/dist/esm/phonetic/Cologne.js.map +1 -0
- package/dist/esm/phonetic/Metaphone.js +174 -0
- package/dist/esm/phonetic/Metaphone.js.map +1 -0
- package/dist/esm/phonetic/Phonetic.js +409 -0
- package/dist/esm/phonetic/Phonetic.js.map +1 -0
- package/dist/esm/phonetic/Soundex.js +137 -0
- package/dist/esm/phonetic/Soundex.js.map +1 -0
- package/dist/esm/utils/DeepMerge.js +139 -0
- package/dist/esm/utils/DeepMerge.js.map +1 -0
- package/dist/esm/utils/DiffChecker.js +498 -0
- package/dist/esm/utils/DiffChecker.js.map +1 -0
- package/dist/esm/utils/Filter.js +187 -0
- package/dist/esm/utils/Filter.js.map +1 -0
- package/dist/esm/utils/HashTable.js +173 -0
- package/dist/esm/utils/HashTable.js.map +1 -0
- package/dist/esm/utils/Normalizer.js +142 -0
- package/dist/esm/utils/Normalizer.js.map +1 -0
- package/dist/esm/utils/Pool.js +194 -0
- package/dist/esm/utils/Pool.js.map +1 -0
- package/dist/esm/utils/Profiler.js +227 -0
- package/dist/esm/utils/Profiler.js.map +1 -0
- package/dist/esm/utils/Registry.js +142 -0
- package/dist/esm/utils/Registry.js.map +1 -0
- package/dist/esm/utils/TextAnalyzer.js +356 -0
- package/dist/esm/utils/TextAnalyzer.js.map +1 -0
- package/dist/types/CmpStr.d.ts +472 -0
- package/dist/types/CmpStrAsync.d.ts +233 -0
- package/dist/types/index.d.ts +51 -0
- package/dist/types/metric/Cosine.d.ts +57 -0
- package/dist/types/metric/DamerauLevenshtein.d.ts +50 -0
- package/dist/types/metric/DiceSorensen.d.ts +57 -0
- package/dist/types/metric/Hamming.d.ts +49 -0
- package/dist/types/metric/Jaccard.d.ts +48 -0
- package/dist/types/metric/JaroWinkler.d.ts +50 -0
- package/dist/types/metric/LCS.d.ts +50 -0
- package/dist/types/metric/Levenshtein.d.ts +50 -0
- package/dist/types/metric/Metric.d.ts +261 -0
- package/dist/types/metric/NeedlemanWunsch.d.ts +47 -0
- package/dist/types/metric/SmithWaterman.d.ts +48 -0
- package/dist/types/metric/index.d.ts +41 -0
- package/dist/types/metric/qGram.d.ts +56 -0
- package/dist/types/phonetic/Cologne.d.ts +46 -0
- package/dist/types/phonetic/Metaphone.d.ts +50 -0
- package/dist/types/phonetic/Phonetic.d.ts +189 -0
- package/dist/types/phonetic/Soundex.d.ts +49 -0
- package/dist/types/phonetic/index.d.ts +30 -0
- package/dist/types/utils/DeepMerge.d.ts +70 -0
- package/dist/types/utils/DiffChecker.d.ts +137 -0
- package/dist/types/utils/Filter.d.ts +97 -0
- package/dist/types/utils/HashTable.d.ts +86 -0
- package/dist/types/utils/Normalizer.d.ts +76 -0
- package/dist/types/utils/Pool.d.ts +63 -0
- package/dist/types/utils/Profiler.d.ts +129 -0
- package/dist/types/utils/Registry.d.ts +57 -0
- package/dist/types/utils/TextAnalyzer.d.ts +199 -0
- package/dist/types/utils/Types.d.ts +313 -0
- package/package.json +62 -49
- package/src/CmpStr.d.ts +0 -70
- package/src/CmpStr.js +0 -912
- package/src/CmpStrAsync.d.ts +0 -19
- package/src/CmpStrAsync.js +0 -204
- package/src/algorithms/cosine.js +0 -86
- package/src/algorithms/damerau.js +0 -78
- package/src/algorithms/dice.js +0 -65
- package/src/algorithms/hamming.js +0 -44
- package/src/algorithms/jaccard.js +0 -34
- package/src/algorithms/jaroWinkler.js +0 -106
- package/src/algorithms/lcs.js +0 -58
- package/src/algorithms/levenshtein.js +0 -70
- package/src/algorithms/needlemanWunsch.js +0 -72
- package/src/algorithms/qGram.js +0 -63
- package/src/algorithms/smithWaterman.js +0 -78
- package/src/algorithms/soundex.js +0 -152
- package/src/index.d.ts +0 -3
- package/src/index.js +0 -47
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types and Interfaces for CmpStr
|
|
3
|
+
* src/utils/Types.ts
|
|
4
|
+
*
|
|
5
|
+
* This file defines all core types, interfaces, and utility type aliases used throughout
|
|
6
|
+
* the CmpStr package. It provides type safety and documentation for all major components,
|
|
7
|
+
* including metrics, phonetic algorithms, filters, normalization, diffing, and profiling.
|
|
8
|
+
*
|
|
9
|
+
* All interfaces are designed for extensibility and clarity, supporting both internal
|
|
10
|
+
* implementation and external usage in user code.
|
|
11
|
+
*
|
|
12
|
+
* @module Utils/Types
|
|
13
|
+
* @author Paul Köhler (komed3)
|
|
14
|
+
* @license MIT
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* ProfilerEntry represents a single profiling result, including execution time,
|
|
18
|
+
* memory usage, the result of the profiled function, and optional metadata.
|
|
19
|
+
*
|
|
20
|
+
* @template T - The type of the profiled result
|
|
21
|
+
*/
|
|
22
|
+
export interface ProfilerEntry<T> {
|
|
23
|
+
time: number;
|
|
24
|
+
mem: number;
|
|
25
|
+
res: T;
|
|
26
|
+
meta?: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* ProfilerService defines the API for the Profiler utility, providing methods
|
|
30
|
+
* to enable/disable profiling, clear results, retrieve reports, and get totals.
|
|
31
|
+
*
|
|
32
|
+
* @template T - The type of the profiled result
|
|
33
|
+
*/
|
|
34
|
+
export interface ProfilerService<T> {
|
|
35
|
+
enable: () => void;
|
|
36
|
+
disable: () => void;
|
|
37
|
+
clear: () => void;
|
|
38
|
+
report: () => ProfilerEntry<T>[];
|
|
39
|
+
last: () => ProfilerEntry<T> | undefined;
|
|
40
|
+
total: () => {
|
|
41
|
+
time: number;
|
|
42
|
+
mem: number;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* PoolType enumerates the supported buffer types for the Pool utility.
|
|
47
|
+
*/
|
|
48
|
+
export type PoolType = 'uint16' | 'number[]' | 'set' | 'map';
|
|
49
|
+
/**
|
|
50
|
+
* PoolConfig defines the configuration for a buffer pool.
|
|
51
|
+
*/
|
|
52
|
+
export interface PoolConfig {
|
|
53
|
+
type: PoolType;
|
|
54
|
+
maxSize: number;
|
|
55
|
+
maxItemSize: number;
|
|
56
|
+
allowOversize: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* PoolBuffer represents a buffer and its size in the pool.
|
|
60
|
+
*
|
|
61
|
+
* @template T - The buffer type
|
|
62
|
+
*/
|
|
63
|
+
export interface PoolBuffer<T> {
|
|
64
|
+
buffer: T;
|
|
65
|
+
size: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* NormalizerFn defines the signature for a normalization function.
|
|
69
|
+
* It takes a string and returns a normalized string.
|
|
70
|
+
*/
|
|
71
|
+
export type NormalizerFn = (input: string) => string;
|
|
72
|
+
/**
|
|
73
|
+
* NormalizeFlags is a string representing a sequence of normalization steps.
|
|
74
|
+
* Each character or substring corresponds to a specific normalization operation.
|
|
75
|
+
*/
|
|
76
|
+
export type NormalizeFlags = string;
|
|
77
|
+
/**
|
|
78
|
+
* FilterFn defines the signature for a filter function.
|
|
79
|
+
* It takes a string and returns the filtered string.
|
|
80
|
+
*/
|
|
81
|
+
export type FilterFn = (input: string) => string;
|
|
82
|
+
/**
|
|
83
|
+
* FilterOptions configures the behavior of a filter entry.
|
|
84
|
+
*/
|
|
85
|
+
export interface FilterOptions {
|
|
86
|
+
priority?: number;
|
|
87
|
+
active?: boolean;
|
|
88
|
+
overrideable?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* FilterEntry represents a single filter in the filter system.
|
|
92
|
+
*/
|
|
93
|
+
export interface FilterEntry {
|
|
94
|
+
id: string;
|
|
95
|
+
fn: FilterFn;
|
|
96
|
+
priority: number;
|
|
97
|
+
active: boolean;
|
|
98
|
+
overrideable: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* RegistryConstructor is a type alias for a class constructor used in registries.
|
|
102
|
+
*
|
|
103
|
+
* @template T - The class type
|
|
104
|
+
*/
|
|
105
|
+
export type RegistryConstructor<T> = abstract new (...args: any[]) => T;
|
|
106
|
+
/**
|
|
107
|
+
* RegistryService defines the API for a generic registry of classes.
|
|
108
|
+
*
|
|
109
|
+
* @template T - The class type managed by the registry
|
|
110
|
+
*/
|
|
111
|
+
export interface RegistryService<T> {
|
|
112
|
+
add: (name: string, cls: RegistryConstructor<T>, update?: boolean) => void;
|
|
113
|
+
remove: (name: string) => void;
|
|
114
|
+
has: (name: string) => boolean;
|
|
115
|
+
get: (name: string) => RegistryConstructor<T>;
|
|
116
|
+
list: () => string[];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* MetricInput represents the input for metric computations.
|
|
120
|
+
* It can be a single string or an array of strings.
|
|
121
|
+
*/
|
|
122
|
+
export type MetricInput = string | string[];
|
|
123
|
+
/**
|
|
124
|
+
* MetricMode specifies the computation mode for metrics.
|
|
125
|
+
* - 'default': single or batch comparison related to input
|
|
126
|
+
* - 'batch': compare multiple strings
|
|
127
|
+
* - 'single': runs a single comparison
|
|
128
|
+
* - 'pairwise': compare arrays element-wise
|
|
129
|
+
*/
|
|
130
|
+
export type MetricMode = 'default' | 'batch' | 'single' | 'pairwise';
|
|
131
|
+
/**
|
|
132
|
+
* MetricOptions configures the behavior of metric computations.
|
|
133
|
+
*/
|
|
134
|
+
export interface MetricOptions {
|
|
135
|
+
mode?: MetricMode;
|
|
136
|
+
delimiter?: string;
|
|
137
|
+
pad?: string;
|
|
138
|
+
q?: number;
|
|
139
|
+
match?: number;
|
|
140
|
+
mismatch?: number;
|
|
141
|
+
gap?: number;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* MetricRaw is a generic record for storing raw metric-specific data.
|
|
145
|
+
*/
|
|
146
|
+
export type MetricRaw = Record<string, any>;
|
|
147
|
+
/**
|
|
148
|
+
* MetricCompute represents the result of a metric computation.
|
|
149
|
+
*
|
|
150
|
+
* @template R - The type of the raw result
|
|
151
|
+
*/
|
|
152
|
+
export interface MetricCompute<R = MetricRaw> {
|
|
153
|
+
res: number;
|
|
154
|
+
raw?: R;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* MetricResultSingle represents the result of a single metric comparison.
|
|
158
|
+
*
|
|
159
|
+
* @template R - The type of the raw result
|
|
160
|
+
*/
|
|
161
|
+
export interface MetricResultSingle<R = MetricRaw> {
|
|
162
|
+
metric: string;
|
|
163
|
+
a: string;
|
|
164
|
+
b: string;
|
|
165
|
+
res: number;
|
|
166
|
+
raw?: R;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* MetricResultBatch is an array of single metric results for batch operations.
|
|
170
|
+
*
|
|
171
|
+
* @template R - The type of the raw result
|
|
172
|
+
*/
|
|
173
|
+
export type MetricResultBatch<R = MetricRaw> = MetricResultSingle<R>[];
|
|
174
|
+
/**
|
|
175
|
+
* MetricResult is a union of single and batch metric results.
|
|
176
|
+
*
|
|
177
|
+
* @template R - The type of the raw result
|
|
178
|
+
*/
|
|
179
|
+
export type MetricResult<R = MetricRaw> = MetricResultSingle<R> | MetricResultBatch<R>;
|
|
180
|
+
/**
|
|
181
|
+
* PhoneticOptions configures the behavior of phonetic algorithms.
|
|
182
|
+
*/
|
|
183
|
+
export interface PhoneticOptions {
|
|
184
|
+
map?: string;
|
|
185
|
+
delimiter?: string;
|
|
186
|
+
length?: number;
|
|
187
|
+
pad?: string;
|
|
188
|
+
dedupe?: boolean;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* PhoneticRule defines a single rule for phonetic mapping.
|
|
192
|
+
*/
|
|
193
|
+
export interface PhoneticRule {
|
|
194
|
+
char: string;
|
|
195
|
+
code: string;
|
|
196
|
+
position?: 'start' | 'middle' | 'end';
|
|
197
|
+
prev?: string[];
|
|
198
|
+
prevNot?: string[];
|
|
199
|
+
prev2?: string[];
|
|
200
|
+
prev2Not?: string[];
|
|
201
|
+
next?: string[];
|
|
202
|
+
nextNot?: string[];
|
|
203
|
+
next2?: string[];
|
|
204
|
+
next2Not?: string[];
|
|
205
|
+
leading?: string;
|
|
206
|
+
trailing?: string;
|
|
207
|
+
match?: string[];
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* PhoneticMap defines a mapping for a specific phonetic algorithm and language.
|
|
211
|
+
*/
|
|
212
|
+
export interface PhoneticMap {
|
|
213
|
+
map: Record<string, string>;
|
|
214
|
+
ruleset?: PhoneticRule[];
|
|
215
|
+
ignore?: string[];
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* PhoneticMapping is a record of named phonetic maps for an algorithm.
|
|
219
|
+
*/
|
|
220
|
+
export type PhoneticMapping = Record<string, PhoneticMap>;
|
|
221
|
+
/**
|
|
222
|
+
* PhoneticMappingService defines the API for managing phonetic mappings.
|
|
223
|
+
*/
|
|
224
|
+
export interface PhoneticMappingService {
|
|
225
|
+
add: (algo: string, id: string, map: PhoneticMap, update?: boolean) => void;
|
|
226
|
+
remove: (algo: string, id: string) => void;
|
|
227
|
+
has: (algo: string, id: string) => boolean;
|
|
228
|
+
get: (algo: string, id: string) => PhoneticMap | undefined;
|
|
229
|
+
list: (algo: string) => string[];
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* DiffMode specifies the granularity for diffing.
|
|
233
|
+
* - 'line': line-based diff
|
|
234
|
+
* - 'word': word-based diff
|
|
235
|
+
*/
|
|
236
|
+
export type DiffMode = 'line' | 'word';
|
|
237
|
+
/**
|
|
238
|
+
* DiffOptions configures the behavior of the DiffChecker utility.
|
|
239
|
+
*/
|
|
240
|
+
export interface DiffOptions {
|
|
241
|
+
mode?: DiffMode;
|
|
242
|
+
caseInsensitive?: boolean;
|
|
243
|
+
contextLines?: number;
|
|
244
|
+
groupedLines?: boolean;
|
|
245
|
+
expandLines?: boolean;
|
|
246
|
+
showChangeMagnitude?: boolean;
|
|
247
|
+
maxMagnitudeSymbols?: number;
|
|
248
|
+
lineBreak?: string;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* DiffEntry represents a single change (insertion or deletion) in a diff.
|
|
252
|
+
*/
|
|
253
|
+
export interface DiffEntry {
|
|
254
|
+
posA: number;
|
|
255
|
+
posB: number;
|
|
256
|
+
del: string;
|
|
257
|
+
ins: string;
|
|
258
|
+
size: number;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* DiffLine represents the diff for a single line, including all changes.
|
|
262
|
+
*/
|
|
263
|
+
export interface DiffLine {
|
|
264
|
+
line: number;
|
|
265
|
+
diffs: DiffEntry[];
|
|
266
|
+
delSize: number;
|
|
267
|
+
insSize: number;
|
|
268
|
+
totalSize: number;
|
|
269
|
+
baseLen: number;
|
|
270
|
+
magnitude: string;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* DiffGroup represents a group of adjacent changed lines in a diff.
|
|
274
|
+
*/
|
|
275
|
+
export interface DiffGroup {
|
|
276
|
+
line: number;
|
|
277
|
+
start: number;
|
|
278
|
+
end: number;
|
|
279
|
+
entries: DiffLine[];
|
|
280
|
+
delSize: number;
|
|
281
|
+
insSize: number;
|
|
282
|
+
totalSize: number;
|
|
283
|
+
magnitude: string;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* CmpStrProcessors defines pre-processors for input strings before comparison.
|
|
287
|
+
*/
|
|
288
|
+
export interface CmpStrProcessors {
|
|
289
|
+
phonetic?: {
|
|
290
|
+
algo: string;
|
|
291
|
+
opt?: PhoneticOptions;
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* CmpStrOptions configures the behavior of a CmpStr instance.
|
|
296
|
+
*/
|
|
297
|
+
export interface CmpStrOptions {
|
|
298
|
+
raw?: boolean;
|
|
299
|
+
removeZero?: boolean;
|
|
300
|
+
flags?: NormalizeFlags;
|
|
301
|
+
metric?: string;
|
|
302
|
+
opt?: MetricOptions;
|
|
303
|
+
processors?: CmpStrProcessors;
|
|
304
|
+
output?: 'orig' | 'prep';
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* CmpStrResult represents a simplified result for user-facing API methods.
|
|
308
|
+
*/
|
|
309
|
+
export interface CmpStrResult {
|
|
310
|
+
source: string;
|
|
311
|
+
target: string;
|
|
312
|
+
match: number;
|
|
313
|
+
}
|
package/package.json
CHANGED
|
@@ -1,49 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cmpstr",
|
|
3
|
-
"description": "lightweight
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"soundex",
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
}
|
|
49
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "cmpstr",
|
|
3
|
+
"description": "CmpStr is a lightweight, fast and well performing package for calculating string similarity",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"version": "3.0.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "komed3 (Paul Köhler)",
|
|
8
|
+
"email": "webmaster@komed3.de",
|
|
9
|
+
"url": "https://komed3.de"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/komed3/cmpstr",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"string-similarity", "string-comparison", "fuzzy-matching", "phonetic-search",
|
|
14
|
+
"phonetic-algorithms", "similarity-metrics", "batch-processing", "text-search",
|
|
15
|
+
"pairwise-comparison", "normalization", "filtering", "text-analysis", "diff",
|
|
16
|
+
"diffing", "typescript", "asynchronous", "custom-algorithms", "metrics",
|
|
17
|
+
"algorithms", "levenshtein", "damerau-levenshtein", "jaro-winkler", "cosine",
|
|
18
|
+
"dice-coefficient", "hamming-distance", "jaccard-index", "needleman-wunsch",
|
|
19
|
+
"lcs", "smith-waterman", "q-gram", "soundex", "metaphone", "cologne-phonetic",
|
|
20
|
+
"profiling", "extensible"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/komed3/cmpstr.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/komed3/cmpstr/issues"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"main": "dist/cjs/index.js",
|
|
35
|
+
"types": "dist/types/index.d.ts",
|
|
36
|
+
"module": "dist/esm/index.js",
|
|
37
|
+
"browser": "dist/CmpStr.umd.min.js",
|
|
38
|
+
"exports": {
|
|
39
|
+
"require": "./dist/cjs/index.js",
|
|
40
|
+
"import": "./dist/esm/index.js"
|
|
41
|
+
},
|
|
42
|
+
"type": "module",
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"build": "rollup -c && tsc --project tsconfig.build.json",
|
|
46
|
+
"lint": "tsc --project tsconfig.lint.json",
|
|
47
|
+
"clean": "rm -rf dist"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
51
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
52
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
53
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
54
|
+
"@types/node": "^22.15.23",
|
|
55
|
+
"prettier": "^3.5.3",
|
|
56
|
+
"rollup": "^4.41.1",
|
|
57
|
+
"rollup-plugin-prettier": "^4.1.2",
|
|
58
|
+
"tslib": "^2.8.1",
|
|
59
|
+
"typescript": "^5.8.3",
|
|
60
|
+
"vitest": "^3.2.2"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/CmpStr.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export interface Config {
|
|
2
|
-
flags?: string;
|
|
3
|
-
threshold?: number;
|
|
4
|
-
options?: Record<string, any>;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface BatchResult {
|
|
8
|
-
target: string;
|
|
9
|
-
match: number | any;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export declare class CmpStr {
|
|
13
|
-
|
|
14
|
-
constructor ( algo?: string, str?: string );
|
|
15
|
-
|
|
16
|
-
isReady () : boolean;
|
|
17
|
-
|
|
18
|
-
setStr ( str: string ) : boolean;
|
|
19
|
-
|
|
20
|
-
getStr () : string;
|
|
21
|
-
|
|
22
|
-
listAlgo ( loadedOnly?: boolean ) : string[];
|
|
23
|
-
|
|
24
|
-
isAlgo ( algo: string ) : boolean;
|
|
25
|
-
|
|
26
|
-
setAlgo ( algo: string ) : boolean;
|
|
27
|
-
|
|
28
|
-
getAlgo () : string;
|
|
29
|
-
|
|
30
|
-
addAlgo ( algo: string, callback: (
|
|
31
|
-
a: string, b: string, ...args : any
|
|
32
|
-
) => number | any, useIt?: boolean ) : boolean;
|
|
33
|
-
|
|
34
|
-
rmvAlgo( algo: string ) : boolean;
|
|
35
|
-
|
|
36
|
-
listFilter () : string[];
|
|
37
|
-
|
|
38
|
-
addFilter ( name: string, callback: (
|
|
39
|
-
str: string
|
|
40
|
-
) => string, priority?: number ) : boolean;
|
|
41
|
-
|
|
42
|
-
rmvFilter ( name: string ) : boolean;
|
|
43
|
-
|
|
44
|
-
pauseFilter ( name: string ) : boolean;
|
|
45
|
-
|
|
46
|
-
resumeFilter ( name: string ) : boolean;
|
|
47
|
-
|
|
48
|
-
clearFilter () : boolean;
|
|
49
|
-
|
|
50
|
-
setFlags( flags: string ) : void;
|
|
51
|
-
|
|
52
|
-
getFlags () : string;
|
|
53
|
-
|
|
54
|
-
normalize ( input: string|string[], flags?: string ) : string|string[];
|
|
55
|
-
|
|
56
|
-
clearCache () : boolean;
|
|
57
|
-
|
|
58
|
-
compare ( algo: string, a: string, b: string, config?: Config ) : number | any;
|
|
59
|
-
|
|
60
|
-
test ( str: string, config?: Config ) : number | any;
|
|
61
|
-
|
|
62
|
-
batchTest ( arr: string[], config?: Config ) : BatchResult[];
|
|
63
|
-
|
|
64
|
-
match ( arr: string[], config?: Config ) : BatchResult[];
|
|
65
|
-
|
|
66
|
-
closest ( arr: string[], config?: Config ) : string | undefined;
|
|
67
|
-
|
|
68
|
-
similarityMatrix ( algo: string, arr: string[], config?: Config ) : number[][];
|
|
69
|
-
|
|
70
|
-
}
|