rapid-fuzzy 1.0.0 → 1.1.1

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/README.md CHANGED
@@ -12,7 +12,7 @@ Blazing-fast fuzzy search for JavaScript — powered by Rust, works everywhere.
12
12
 
13
13
  ## Features
14
14
 
15
- - **Fast**: Up to 7,000x faster than fuse.js with FuzzyIndex (Rust + napi-rs)
15
+ - **Fast**: Up to 15,000x faster than fuse.js in indexed mode on large datasets (Rust + napi-rs) — [see benchmarks](#benchmarks)
16
16
  - **Universal**: Works in Node.js (native), browsers (WASM), Deno, and Bun
17
17
  - **Zero JS dependencies**: Pure Rust core with napi-rs bindings
18
18
  - **Type-safe**: Full TypeScript support with auto-generated type definitions
@@ -31,7 +31,7 @@ const results = search('typscript', ['TypeScript', 'JavaScript', 'Python']);
31
31
  // → [{ item: 'TypeScript', score: 0.85, index: 0 }, ...]
32
32
  ```
33
33
 
34
- For repeated searches, use `FuzzyIndex` for up to 165x faster lookups:
34
+ For repeated searches, use `FuzzyIndex` for up to 297x faster lookups:
35
35
 
36
36
  ```typescript
37
37
  import { FuzzyIndex } from 'rapid-fuzzy';
@@ -51,7 +51,7 @@ pnpm add rapid-fuzzy
51
51
  ### Runtime-specific notes
52
52
 
53
53
  - **Node.js** (>=20): Uses native bindings via napi-rs for best performance.
54
- - **Browser / Deno / Bun**: Falls back to a WASM build automatically. The WASM binary is ~607 KB raw (~200 KB gzipped).
54
+ - **Browser / Deno / Bun**: Falls back to a WASM build automatically. The WASM binary is ~660 KB raw (~230 KB gzipped).
55
55
 
56
56
  > **Browser WASM requirement**: The WASM build uses `SharedArrayBuffer` for threading, which requires the following HTTP headers on your page:
57
57
  > ```
@@ -60,6 +60,32 @@ pnpm add rapid-fuzzy
60
60
  > ```
61
61
  > Without these headers, you will see `SharedArrayBuffer is not defined`. See [MDN: SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements) for details.
62
62
 
63
+ ### Framework Integration (SSR)
64
+
65
+ Native modules need to be externalized in SSR frameworks:
66
+
67
+ **Next.js**
68
+
69
+ ```js
70
+ // next.config.js
71
+ const nextConfig = {
72
+ serverExternalPackages: ['rapid-fuzzy'],
73
+ };
74
+ ```
75
+
76
+ **Vite SSR**
77
+
78
+ ```js
79
+ // vite.config.js
80
+ export default {
81
+ ssr: {
82
+ external: ['rapid-fuzzy'],
83
+ },
84
+ };
85
+ ```
86
+
87
+ On the client side, rapid-fuzzy automatically falls back to WASM — no additional configuration needed beyond the SharedArrayBuffer headers above.
88
+
63
89
  ## API
64
90
 
65
91
  ### Fuzzy Search
@@ -86,6 +112,9 @@ const [match] = search('hlo', ['hello world'], { includePositions: true });
86
112
  // Case-sensitive matching (default: smart case)
87
113
  search('Type', items, { isCaseSensitive: true });
88
114
 
115
+ // Return all items when query is empty (useful for filter-as-you-type UIs)
116
+ search('', items, { returnAllOnEmpty: true });
117
+
89
118
  // Find the single best match
90
119
  closest('tsc', ['TypeScript', 'JavaScript', 'Python']);
91
120
  // → 'TypeScript'
@@ -98,11 +127,12 @@ closest('xyz', items, 0.5);
98
127
  ### String Distance
99
128
 
100
129
  ```typescript
101
- import { levenshtein, jaroWinkler, sorensenDice } from 'rapid-fuzzy';
130
+ import { levenshtein, jaroWinkler, sorensenDice, hamming } from 'rapid-fuzzy';
102
131
 
103
132
  levenshtein('kitten', 'sitting'); // 3
104
133
  jaroWinkler('MARTHA', 'MARHTA'); // 0.961
105
134
  sorensenDice('night', 'nacht'); // 0.25
135
+ hamming('karolin', 'kathrin'); // 3 (null if lengths differ)
106
136
  ```
107
137
 
108
138
  ### Query Syntax
@@ -159,12 +189,16 @@ For applications that search the same dataset repeatedly (autocomplete, file fin
159
189
  ```typescript
160
190
  import { FuzzyIndex, FuzzyObjectIndex } from 'rapid-fuzzy';
161
191
 
162
- // String search index — up to 165x faster than standalone search()
192
+ // String search index — up to 297x faster than standalone search()
163
193
  const index = new FuzzyIndex(['TypeScript', 'JavaScript', 'Python', ...]);
164
194
 
165
195
  index.search('typscript', { maxResults: 5 });
166
196
  index.closest('tsc');
167
197
 
198
+ // Index-only results (no string cloning — less GC pressure)
199
+ const hits = index.searchIndices('typscript', { maxResults: 5 });
200
+ // → [{ index: 0, score: 0.85, positions: [] }, ...]
201
+
168
202
  // Mutate the index without rebuilding
169
203
  index.add('Rust');
170
204
  index.remove(2); // swap-remove by index
@@ -184,6 +218,34 @@ index.destroy();
184
218
  userIndex.destroy();
185
219
  ```
186
220
 
221
+ #### Incremental Search (Autocomplete)
222
+
223
+ FuzzyIndex automatically caches matching candidates. When a new query extends the previous one, only cached candidates are re-scored:
224
+
225
+ ```typescript
226
+ const index = new FuzzyIndex(items);
227
+ index.search('app'); // scores all items, caches matches
228
+ index.search('apple'); // only re-scores cached candidates — much faster
229
+ index.search('xyz'); // different query — full scan, new cache
230
+ ```
231
+
232
+ This makes FuzzyIndex ideal for search-as-you-type UIs where each keystroke extends the query.
233
+
234
+ #### Index Serialization
235
+
236
+ Save a FuzzyIndex to avoid rebuilding on startup:
237
+
238
+ ```typescript
239
+ const buffer = index.serialize();
240
+ fs.writeFileSync('search-index.bin', buffer);
241
+
242
+ // Load later (faster than rebuilding from scratch)
243
+ const restored = FuzzyIndex.deserialize(fs.readFileSync('search-index.bin'));
244
+ restored.search('query');
245
+ ```
246
+
247
+ > **Note:** The serialization format is version-specific. Regenerate the index after updating rapid-fuzzy.
248
+
187
249
  ### Match Highlighting
188
250
 
189
251
  Convert matched positions into highlighted markup for UI rendering:
@@ -255,6 +317,10 @@ levenshteinBatch([
255
317
  // Compare one string against many candidates
256
318
  levenshteinMany('kitten', ['sitting', 'kittens', 'kitchen']);
257
319
  // → [3, 1, 2]
320
+
321
+ // With early-termination threshold (skip candidates that can't match)
322
+ levenshteinMany('kitten', candidates, 3); // maxDistance → returns 4 for exceeding
323
+ jaroWinklerMany('MARTHA', candidates, 0.8); // minSimilarity → returns 0.0 for below
258
324
  ```
259
325
 
260
326
  > **Tip**: Prefer batch/many variants over calling single-pair functions in a loop — they are significantly faster for multiple comparisons.
@@ -266,6 +332,7 @@ levenshteinMany('kitten', ['sitting', 'kittens', 'kitchen']);
266
332
  | Use case | Recommended | Why |
267
333
  |---|---|---|
268
334
  | Typo detection / spell check | `levenshtein`, `damerauLevenshtein` | Counts edits; Damerau adds transposition support |
335
+ | Fixed-length comparison | `hamming` | Counts differing positions; only for equal-length strings |
269
336
  | Name / address matching | `jaroWinkler`, `tokenSortRatio` | Prefix-weighted or order-independent matching |
270
337
  | Document / text similarity | `sorensenDice` | Bigram-based; handles longer text well |
271
338
  | Normalized comparison (0–1) | `normalizedLevenshtein` | Length-independent similarity score |
@@ -273,11 +340,11 @@ levenshteinMany('kitten', ['sitting', 'kittens', 'kitchen']);
273
340
  | Substring / abbreviation matching | `partialRatio` | Finds best partial match within longer strings |
274
341
  | Best-effort similarity | `weightedRatio` | Picks the best score across all methods automatically |
275
342
  | Interactive fuzzy search | `search`, `closest` | Nucleo algorithm (same as Helix editor) |
276
- | Repeated search on same data | `FuzzyIndex`, `FuzzyObjectIndex` | Persistent Rust-side index with incremental cache, up to 165x faster |
343
+ | Repeated search on same data | `FuzzyIndex`, `FuzzyObjectIndex` | Persistent Rust-side index with incremental cache, up to 297x faster |
277
344
 
278
345
  **Return types:**
279
346
 
280
- - `levenshtein`, `damerauLevenshtein` → integer (edit count)
347
+ - `levenshtein`, `damerauLevenshtein`, `hamming` → integer (edit/difference count; `hamming` returns `null` if lengths differ)
281
348
  - `jaro`, `jaroWinkler`, `sorensenDice`, `normalizedLevenshtein` → float between 0.0 (no match) and 1.0 (identical)
282
349
  - `tokenSortRatio`, `tokenSetRatio`, `partialRatio`, `weightedRatio` → float between 0.0 and 1.0
283
350
  - `search` → array of `{ item, score, index, positions }` sorted by relevance (score: 0.0–1.0)
@@ -295,15 +362,16 @@ Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.
295
362
 
296
363
  | Function | rapid-fuzzy | fastest-levenshtein | leven | string-similarity |
297
364
  |---|---:|---:|---:|---:|
298
- | Levenshtein | 564,605 ops/s | **758,533 ops/s** | 214,205 ops/s | — |
299
- | Normalized Levenshtein | **515,352 ops/s** | — | — | — |
300
- | Sorensen-Dice | **152,317 ops/s** | — | — | 86,399 ops/s |
301
- | Jaro-Winkler | **523,894 ops/s** | — | — | — |
302
- | Damerau-Levenshtein | **118,113 ops/s** | — | — | — |
365
+ | Levenshtein | 545,338 ops/s | **741,195 ops/s** | 225,457 ops/s | — |
366
+ | Normalized Levenshtein | **514,446 ops/s** | — | — | — |
367
+ | Sorensen-Dice | **142,180 ops/s** | — | — | 56,729 ops/s |
368
+ | Jaro-Winkler | **505,762 ops/s** | — | — | — |
369
+ | Damerau-Levenshtein | **116,186 ops/s** | — | — | — |
370
+ | Hamming | **883,614 ops/s** | — | — | — |
303
371
 
304
372
  </details>
305
373
 
306
- > **Note**: For single-pair Levenshtein, fastest-levenshtein is ~1.4x faster due to its optimized pure-JS implementation that avoids FFI overhead. rapid-fuzzy is **2.5x faster** than leven, and provides broader algorithm coverage plus batch / search scenarios.
374
+ > **Note**: For single-pair Levenshtein, fastest-levenshtein is ~1.4x faster due to its optimized pure-JS implementation that avoids FFI overhead. rapid-fuzzy is **2.4x faster** than leven, and provides broader algorithm coverage plus batch / search scenarios.
307
375
 
308
376
  ### Search Performance
309
377
 
@@ -316,9 +384,9 @@ Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.
316
384
 
317
385
  | Dataset size | rapid-fuzzy | rapid-fuzzy (indexed) | fuse.js | fuzzysort | uFuzzy |
318
386
  |---|---:|---:|---:|---:|---:|
319
- | Small (20 items) | 287,682 ops/s | 404,271 ops/s | 126,591 ops/s | **2,655,421 ops/s** | 927,173 ops/s |
320
- | Medium (1K items) | 6,827 ops/s | **79,616 ops/s** | 366 ops/s | 63,831 ops/s | 30,099 ops/s |
321
- | Large (10K items) | 827 ops/s | **136,294 ops/s** | 18 ops/s | 27,897 ops/s | 6,461 ops/s |
387
+ | Small (20 items) | 279,509 ops/s | 395,932 ops/s | 118,443 ops/s | **1,661,273 ops/s** | 422,032 ops/s |
388
+ | Medium (1K items) | 6,274 ops/s | **77,271 ops/s** | 358 ops/s | 58,123 ops/s | 26,052 ops/s |
389
+ | Large (10K items) | 777 ops/s | **230,848 ops/s** | 15 ops/s | 25,315 ops/s | 4,663 ops/s |
322
390
 
323
391
  </details>
324
392
 
@@ -326,22 +394,22 @@ Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.
326
394
 
327
395
  | Dataset size | rapid-fuzzy | rapid-fuzzy (indexed) | fastest-levenshtein |
328
396
  |---|---:|---:|---:|
329
- | Medium (1K items) | 8,194 ops/s | **978,009 ops/s** | 6,869 ops/s |
330
- | Large (10K items) | 892 ops/s | **152,196 ops/s** | 679 ops/s |
397
+ | Medium (1K items) | 7,690 ops/s | **906,274 ops/s** | 3,536 ops/s |
398
+ | Large (10K items) | 611 ops/s | **352,688 ops/s** | 620 ops/s |
331
399
 
332
- > In indexed mode (`FuzzyIndex`), rapid-fuzzy is up to **224x faster** than fastest-levenshtein for closest-match lookups.
400
+ > In indexed mode (`FuzzyIndex`), rapid-fuzzy is up to **569x faster** than fastest-levenshtein for closest-match lookups.
333
401
 
334
402
  ### Key takeaways
335
403
 
336
- - **vs fuse.js**: `FuzzyIndex` is **218x7,572x faster** depending on dataset size. Even standalone `search()` is 1946x faster.
337
- - **Indexed mode**: `FuzzyIndex` keeps data on the Rust side with incremental caching — **165x faster** than standalone `search()` on large datasets, delivering sub-millisecond autocomplete.
338
- - **vs fuzzysort / uFuzzy**: `FuzzyIndex` outperforms both on 1K+ datasets (up to 4.9x vs fuzzysort, 21x vs uFuzzy).
404
+ - **vs fuse.js**: `FuzzyIndex` is **216x15,390x faster** depending on dataset size. Even standalone `search()` is 1852x faster.
405
+ - **Indexed mode**: `FuzzyIndex` keeps data on the Rust side with incremental caching — **297x faster** than standalone `search()` on large datasets, delivering sub-millisecond autocomplete.
406
+ - **vs fuzzysort / uFuzzy**: `FuzzyIndex` outperforms both on 1K+ datasets (up to 9.1x vs fuzzysort, 50x vs uFuzzy).
339
407
 
340
408
  ## Why rapid-fuzzy?
341
409
 
342
410
  | | rapid-fuzzy | fuse.js | fastest-levenshtein | fuzzysort | uFuzzy |
343
411
  |---|:---:|:---:|:---:|:---:|:---:|
344
- | **Algorithms** | 9 (Levenshtein, Jaro, Dice, …) | Bitap | Levenshtein | Substring | Regex-based |
412
+ | **Algorithms** | 10 (Levenshtein, Hamming, Jaro, Dice, …) | Bitap | Levenshtein | Substring | Regex-based |
345
413
  | **Runtime** | Rust native + WASM | Pure JS | Pure JS | Pure JS | Pure JS |
346
414
  | **Object search** | ✅ weighted keys | ✅ | — | ✅ | — |
347
415
  | **Persistent index** | ✅ FuzzyIndex / FuzzyObjectIndex | — | — | ✅ prepared targets | — |
@@ -353,7 +421,7 @@ Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.
353
421
  | **Highlight utility** | ✅ | — | — | ✅ | ✅ |
354
422
  | **Batch API** | ✅ | — | — | — | — |
355
423
  | **Node.js native** | ✅ napi-rs | — | — | — | — |
356
- | **Browser** | ✅ WASM (~200 KB gzipped) | ✅ | ✅ | ✅ | ✅ |
424
+ | **Browser** | ✅ WASM (~230 KB gzipped) | ✅ | ✅ | ✅ | ✅ |
357
425
  | **TypeScript** | ✅ full | ✅ full | ✅ | ✅ | ✅ |
358
426
 
359
427
  ## Migration Guides
@@ -361,9 +429,9 @@ Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.
361
429
  Switching from another library? These guides provide API mapping tables, code examples, and performance comparisons:
362
430
 
363
431
  - [**From string-similarity**](docs/migration/from-string-similarity.md) — Same Dice coefficient algorithm, now maintained and faster
364
- - [**From fuse.js**](docs/migration/from-fuse-js.md) — Up to 7,000x faster fuzzy search with FuzzyIndex
432
+ - [**From fuse.js**](docs/migration/from-fuse-js.md) — Up to 15,000x faster fuzzy search with FuzzyIndex
365
433
  - [**From leven / fastest-levenshtein**](docs/migration/from-leven.md) — Multi-algorithm upgrade with batch APIs
366
- - [**From fuzzysort**](docs/migration/from-fuzzysort.md) — Richer matching with query syntax and 9 distance algorithms
434
+ - [**From fuzzysort**](docs/migration/from-fuzzysort.md) — Richer matching with query syntax and 10 distance algorithms
367
435
  - [**From uFuzzy**](docs/migration/from-ufuzzy.md) — Weighted object search, batch APIs, and persistent indexes
368
436
 
369
437
  ## License
@@ -0,0 +1,2 @@
1
+ export { highlight, highlightRanges } from './highlight.js';
2
+ export type { HighlightRange } from './highlight.js';
package/index.d.mts CHANGED
@@ -1,11 +1,11 @@
1
- export * from './index.d.ts';
2
- export { highlight, highlightRanges } from './highlight.d.ts';
3
- export type { HighlightRange } from './highlight.d.ts';
4
- export { searchObjects, FuzzyObjectIndex } from './objects';
1
+ export * from './index.js';
2
+ export { highlight, highlightRanges } from './highlight.js';
3
+ export type { HighlightRange } from './highlight.js';
4
+ export { searchObjects, FuzzyObjectIndex } from './objects.js';
5
5
  export type {
6
6
  KeyConfig,
7
7
  ObjectSearchOptions,
8
8
  ObjectSearchResult,
9
9
  ObjectIndexOptions,
10
10
  ObjectIndexSearchOptions,
11
- } from './objects';
11
+ } from './objects.js';
package/index.d.ts CHANGED
@@ -29,6 +29,14 @@ export declare class FuzzyIndex {
29
29
  * If minScore is provided, returns null when the best match scores below the threshold.
30
30
  */
31
31
  closest(query: string, minScore?: number | undefined | null): string | null
32
+ /**
33
+ * Search the index, returning only indices and scores (no item strings).
34
+ *
35
+ * This is more efficient than `search()` when you maintain your own data
36
+ * array and only need the index to look up the original item. Avoids
37
+ * String cloning overhead for each result.
38
+ */
39
+ searchIndices(query: string, options?: number | SearchOptions | undefined | null): Array<IndexSearchResult>
32
40
  /** Add a single item to the index. */
33
41
  add(item: string): void
34
42
  /** Add multiple items to the index at once. */
@@ -36,7 +44,7 @@ export declare class FuzzyIndex {
36
44
  /**
37
45
  * Remove the item at the given index.
38
46
  *
39
- * Returns false if the index is out of bounds.
47
+ * Uses swap-remove for O(1) performance. Returns false if out of bounds.
40
48
  */
41
49
  remove(index: number): boolean
42
50
  /** Free the internal data. After calling this, the index is empty. */
@@ -137,8 +145,62 @@ export declare function damerauLevenshteinBatch(pairs: Array<Array<string>>): Ar
137
145
  * Compute the Damerau-Levenshtein distance from one reference string to many candidates.
138
146
  *
139
147
  * Returns an array of distances, one per candidate, in the same order as the input.
148
+ * If `max_distance` is provided, candidates with distance exceeding the threshold
149
+ * will return `max_distance + 1` (enabling early termination for better performance).
150
+ */
151
+ export declare function damerauLevenshteinMany(reference: string, candidates: Array<string>, maxDistance?: number | undefined | null): Array<number>
152
+
153
+ /**
154
+ * Compute the Hamming distance between two strings.
155
+ *
156
+ * The Hamming distance counts the number of positions at which the corresponding
157
+ * characters differ. It is only defined for strings of equal length.
158
+ * Returns `null` if the strings have different lengths.
159
+ */
160
+ export declare function hamming(a: string, b: string): number | null
161
+
162
+ /**
163
+ * Compute the Hamming distance for multiple pairs of strings in a single call.
164
+ *
165
+ * Returns an array of distances in the same order as the input pairs.
166
+ * Each pair must be an array of exactly two strings `[a, b]`.
167
+ * Returns `null` for pairs with different lengths.
168
+ */
169
+ export declare function hammingBatch(pairs: Array<Array<string>>): Array<number | undefined | null>
170
+
171
+ /**
172
+ * Compute the Hamming distance from one reference string to many candidates.
173
+ *
174
+ * Returns an array of distances, one per candidate, in the same order as the input.
175
+ * Returns `null` for candidates with a different length than the reference.
176
+ * If `max_distance` is provided, candidates with distance exceeding the threshold
177
+ * will also return `null` (enabling early termination for better performance).
140
178
  */
141
- export declare function damerauLevenshteinMany(reference: string, candidates: Array<string>): Array<number>
179
+ export declare function hammingMany(reference: string, candidates: Array<string>, maxDistance?: number | undefined | null): Array<number | undefined | null>
180
+
181
+ /**
182
+ * A lightweight search result containing only index and score (no item string).
183
+ *
184
+ * Use this when you maintain your own data array and only need the index
185
+ * to look up the original item. Avoids String cloning overhead.
186
+ */
187
+ export interface IndexSearchResult {
188
+ /** The index of the item in the original input array. */
189
+ index: number
190
+ /** The match score normalized to 0.0-1.0 range (1.0 is a perfect match). */
191
+ score: number
192
+ /**
193
+ * Indices of matched characters in the item string.
194
+ * Empty unless `includePositions` is set to true in SearchOptions.
195
+ */
196
+ positions: Array<number>
197
+ /**
198
+ * How the query matched this item (Exact, Prefix, Contains, or Fuzzy).
199
+ * Only present when `includePositions` is set to true in SearchOptions.
200
+ * Derived from positions at zero additional cost.
201
+ */
202
+ matchType?: MatchType
203
+ }
142
204
 
143
205
  /**
144
206
  * Compute the Jaro similarity between two strings.
@@ -158,8 +220,10 @@ export declare function jaroBatch(pairs: Array<Array<string>>): Array<number>
158
220
  * Compute the Jaro similarity from one reference string to many candidates.
159
221
  *
160
222
  * Returns an array of similarity scores, one per candidate, in the same order as the input.
223
+ * If `min_similarity` is provided, candidates with similarity below the threshold
224
+ * will return `0.0` (enabling early termination for better performance).
161
225
  */
162
- export declare function jaroMany(reference: string, candidates: Array<string>): Array<number>
226
+ export declare function jaroMany(reference: string, candidates: Array<string>, minSimilarity?: number | undefined | null): Array<number>
163
227
 
164
228
  /**
165
229
  * Compute the Jaro-Winkler similarity between two strings.
@@ -180,8 +244,10 @@ export declare function jaroWinklerBatch(pairs: Array<Array<string>>): Array<num
180
244
  * Compute the Jaro-Winkler similarity from one reference string to many candidates.
181
245
  *
182
246
  * Returns an array of similarity scores, one per candidate, in the same order as the input.
247
+ * If `min_similarity` is provided, candidates with similarity below the threshold
248
+ * will return `0.0` (enabling early termination for better performance).
183
249
  */
184
- export declare function jaroWinklerMany(reference: string, candidates: Array<string>): Array<number>
250
+ export declare function jaroWinklerMany(reference: string, candidates: Array<string>, minSimilarity?: number | undefined | null): Array<number>
185
251
 
186
252
  /** A single result from multi-key fuzzy search. */
187
253
  export interface KeySearchResult {
@@ -217,8 +283,10 @@ export declare function levenshteinBatch(pairs: Array<Array<string>>): Array<num
217
283
  * Compute the Levenshtein distance from one reference string to many candidates.
218
284
  *
219
285
  * Returns an array of distances, one per candidate, in the same order as the input.
286
+ * If `max_distance` is provided, candidates with distance exceeding the threshold
287
+ * will return `max_distance + 1` (enabling early termination for better performance).
220
288
  */
221
- export declare function levenshteinMany(reference: string, candidates: Array<string>): Array<number>
289
+ export declare function levenshteinMany(reference: string, candidates: Array<string>, maxDistance?: number | undefined | null): Array<number>
222
290
 
223
291
  /**
224
292
  * Classification of how a query matched an item.
@@ -254,8 +322,10 @@ export declare function normalizedLevenshteinBatch(pairs: Array<Array<string>>):
254
322
  * Compute the normalized Levenshtein similarity from one reference string to many candidates.
255
323
  *
256
324
  * Returns an array of similarity scores, one per candidate, in the same order as the input.
325
+ * If `min_similarity` is provided, candidates with similarity below the threshold
326
+ * will return `0.0` (enabling early termination for better performance).
257
327
  */
258
- export declare function normalizedLevenshteinMany(reference: string, candidates: Array<string>): Array<number>
328
+ export declare function normalizedLevenshteinMany(reference: string, candidates: Array<string>, minSimilarity?: number | undefined | null): Array<number>
259
329
 
260
330
  /**
261
331
  * Compute the partial ratio between two strings.
package/index.js CHANGED
@@ -77,8 +77,8 @@ function requireNative() {
77
77
  try {
78
78
  const binding = require('rapid-fuzzy-android-arm64')
79
79
  const bindingPackageVersion = require('rapid-fuzzy-android-arm64/package.json').version
80
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
80
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
82
82
  }
83
83
  return binding
84
84
  } catch (e) {
@@ -93,8 +93,8 @@ function requireNative() {
93
93
  try {
94
94
  const binding = require('rapid-fuzzy-android-arm-eabi')
95
95
  const bindingPackageVersion = require('rapid-fuzzy-android-arm-eabi/package.json').version
96
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
96
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
98
  }
99
99
  return binding
100
100
  } catch (e) {
@@ -114,8 +114,8 @@ function requireNative() {
114
114
  try {
115
115
  const binding = require('rapid-fuzzy-win32-x64-gnu')
116
116
  const bindingPackageVersion = require('rapid-fuzzy-win32-x64-gnu/package.json').version
117
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
117
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
119
119
  }
120
120
  return binding
121
121
  } catch (e) {
@@ -130,8 +130,8 @@ function requireNative() {
130
130
  try {
131
131
  const binding = require('rapid-fuzzy-win32-x64-msvc')
132
132
  const bindingPackageVersion = require('rapid-fuzzy-win32-x64-msvc/package.json').version
133
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
133
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
135
135
  }
136
136
  return binding
137
137
  } catch (e) {
@@ -147,8 +147,8 @@ function requireNative() {
147
147
  try {
148
148
  const binding = require('rapid-fuzzy-win32-ia32-msvc')
149
149
  const bindingPackageVersion = require('rapid-fuzzy-win32-ia32-msvc/package.json').version
150
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
152
  }
153
153
  return binding
154
154
  } catch (e) {
@@ -163,8 +163,8 @@ function requireNative() {
163
163
  try {
164
164
  const binding = require('rapid-fuzzy-win32-arm64-msvc')
165
165
  const bindingPackageVersion = require('rapid-fuzzy-win32-arm64-msvc/package.json').version
166
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
166
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
168
  }
169
169
  return binding
170
170
  } catch (e) {
@@ -182,8 +182,8 @@ function requireNative() {
182
182
  try {
183
183
  const binding = require('rapid-fuzzy-darwin-universal')
184
184
  const bindingPackageVersion = require('rapid-fuzzy-darwin-universal/package.json').version
185
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
185
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
187
  }
188
188
  return binding
189
189
  } catch (e) {
@@ -198,8 +198,8 @@ function requireNative() {
198
198
  try {
199
199
  const binding = require('rapid-fuzzy-darwin-x64')
200
200
  const bindingPackageVersion = require('rapid-fuzzy-darwin-x64/package.json').version
201
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
201
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
203
  }
204
204
  return binding
205
205
  } catch (e) {
@@ -214,8 +214,8 @@ function requireNative() {
214
214
  try {
215
215
  const binding = require('rapid-fuzzy-darwin-arm64')
216
216
  const bindingPackageVersion = require('rapid-fuzzy-darwin-arm64/package.json').version
217
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
217
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
219
  }
220
220
  return binding
221
221
  } catch (e) {
@@ -234,8 +234,8 @@ function requireNative() {
234
234
  try {
235
235
  const binding = require('rapid-fuzzy-freebsd-x64')
236
236
  const bindingPackageVersion = require('rapid-fuzzy-freebsd-x64/package.json').version
237
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
239
  }
240
240
  return binding
241
241
  } catch (e) {
@@ -250,8 +250,8 @@ function requireNative() {
250
250
  try {
251
251
  const binding = require('rapid-fuzzy-freebsd-arm64')
252
252
  const bindingPackageVersion = require('rapid-fuzzy-freebsd-arm64/package.json').version
253
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
253
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
255
  }
256
256
  return binding
257
257
  } catch (e) {
@@ -271,8 +271,8 @@ function requireNative() {
271
271
  try {
272
272
  const binding = require('rapid-fuzzy-linux-x64-musl')
273
273
  const bindingPackageVersion = require('rapid-fuzzy-linux-x64-musl/package.json').version
274
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
274
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
276
276
  }
277
277
  return binding
278
278
  } catch (e) {
@@ -287,8 +287,8 @@ function requireNative() {
287
287
  try {
288
288
  const binding = require('rapid-fuzzy-linux-x64-gnu')
289
289
  const bindingPackageVersion = require('rapid-fuzzy-linux-x64-gnu/package.json').version
290
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
290
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
292
292
  }
293
293
  return binding
294
294
  } catch (e) {
@@ -305,8 +305,8 @@ function requireNative() {
305
305
  try {
306
306
  const binding = require('rapid-fuzzy-linux-arm64-musl')
307
307
  const bindingPackageVersion = require('rapid-fuzzy-linux-arm64-musl/package.json').version
308
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
308
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
310
  }
311
311
  return binding
312
312
  } catch (e) {
@@ -321,8 +321,8 @@ function requireNative() {
321
321
  try {
322
322
  const binding = require('rapid-fuzzy-linux-arm64-gnu')
323
323
  const bindingPackageVersion = require('rapid-fuzzy-linux-arm64-gnu/package.json').version
324
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
324
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
326
  }
327
327
  return binding
328
328
  } catch (e) {
@@ -339,8 +339,8 @@ function requireNative() {
339
339
  try {
340
340
  const binding = require('rapid-fuzzy-linux-arm-musleabihf')
341
341
  const bindingPackageVersion = require('rapid-fuzzy-linux-arm-musleabihf/package.json').version
342
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
342
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
344
  }
345
345
  return binding
346
346
  } catch (e) {
@@ -355,8 +355,8 @@ function requireNative() {
355
355
  try {
356
356
  const binding = require('rapid-fuzzy-linux-arm-gnueabihf')
357
357
  const bindingPackageVersion = require('rapid-fuzzy-linux-arm-gnueabihf/package.json').version
358
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
358
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
360
  }
361
361
  return binding
362
362
  } catch (e) {
@@ -373,8 +373,8 @@ function requireNative() {
373
373
  try {
374
374
  const binding = require('rapid-fuzzy-linux-loong64-musl')
375
375
  const bindingPackageVersion = require('rapid-fuzzy-linux-loong64-musl/package.json').version
376
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
376
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
378
  }
379
379
  return binding
380
380
  } catch (e) {
@@ -389,8 +389,8 @@ function requireNative() {
389
389
  try {
390
390
  const binding = require('rapid-fuzzy-linux-loong64-gnu')
391
391
  const bindingPackageVersion = require('rapid-fuzzy-linux-loong64-gnu/package.json').version
392
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
392
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
394
  }
395
395
  return binding
396
396
  } catch (e) {
@@ -407,8 +407,8 @@ function requireNative() {
407
407
  try {
408
408
  const binding = require('rapid-fuzzy-linux-riscv64-musl')
409
409
  const bindingPackageVersion = require('rapid-fuzzy-linux-riscv64-musl/package.json').version
410
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
410
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
412
  }
413
413
  return binding
414
414
  } catch (e) {
@@ -423,8 +423,8 @@ function requireNative() {
423
423
  try {
424
424
  const binding = require('rapid-fuzzy-linux-riscv64-gnu')
425
425
  const bindingPackageVersion = require('rapid-fuzzy-linux-riscv64-gnu/package.json').version
426
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
426
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
428
  }
429
429
  return binding
430
430
  } catch (e) {
@@ -440,8 +440,8 @@ function requireNative() {
440
440
  try {
441
441
  const binding = require('rapid-fuzzy-linux-ppc64-gnu')
442
442
  const bindingPackageVersion = require('rapid-fuzzy-linux-ppc64-gnu/package.json').version
443
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
445
445
  }
446
446
  return binding
447
447
  } catch (e) {
@@ -456,8 +456,8 @@ function requireNative() {
456
456
  try {
457
457
  const binding = require('rapid-fuzzy-linux-s390x-gnu')
458
458
  const bindingPackageVersion = require('rapid-fuzzy-linux-s390x-gnu/package.json').version
459
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
459
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
461
  }
462
462
  return binding
463
463
  } catch (e) {
@@ -476,8 +476,8 @@ function requireNative() {
476
476
  try {
477
477
  const binding = require('rapid-fuzzy-openharmony-arm64')
478
478
  const bindingPackageVersion = require('rapid-fuzzy-openharmony-arm64/package.json').version
479
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
481
  }
482
482
  return binding
483
483
  } catch (e) {
@@ -492,8 +492,8 @@ function requireNative() {
492
492
  try {
493
493
  const binding = require('rapid-fuzzy-openharmony-x64')
494
494
  const bindingPackageVersion = require('rapid-fuzzy-openharmony-x64/package.json').version
495
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
497
  }
498
498
  return binding
499
499
  } catch (e) {
@@ -508,8 +508,8 @@ function requireNative() {
508
508
  try {
509
509
  const binding = require('rapid-fuzzy-openharmony-arm')
510
510
  const bindingPackageVersion = require('rapid-fuzzy-openharmony-arm/package.json').version
511
- if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
- throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
511
+ if (bindingPackageVersion !== '1.1.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
+ throw new Error(`Native binding package version mismatch, expected 1.1.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
513
  }
514
514
  return binding
515
515
  } catch (e) {
@@ -582,6 +582,9 @@ module.exports.closest = nativeBinding.closest
582
582
  module.exports.damerauLevenshtein = nativeBinding.damerauLevenshtein
583
583
  module.exports.damerauLevenshteinBatch = nativeBinding.damerauLevenshteinBatch
584
584
  module.exports.damerauLevenshteinMany = nativeBinding.damerauLevenshteinMany
585
+ module.exports.hamming = nativeBinding.hamming
586
+ module.exports.hammingBatch = nativeBinding.hammingBatch
587
+ module.exports.hammingMany = nativeBinding.hammingMany
585
588
  module.exports.jaro = nativeBinding.jaro
586
589
  module.exports.jaroBatch = nativeBinding.jaroBatch
587
590
  module.exports.jaroMany = nativeBinding.jaroMany
package/index.mjs CHANGED
@@ -12,6 +12,9 @@ export const {
12
12
  damerauLevenshtein,
13
13
  damerauLevenshteinBatch,
14
14
  damerauLevenshteinMany,
15
+ hamming,
16
+ hammingBatch,
17
+ hammingMany,
15
18
  jaro,
16
19
  jaroBatch,
17
20
  jaroMany,
package/objects.d.mts ADDED
@@ -0,0 +1,8 @@
1
+ export { searchObjects, FuzzyObjectIndex } from './objects.js';
2
+ export type {
3
+ KeyConfig,
4
+ ObjectSearchOptions,
5
+ ObjectSearchResult,
6
+ ObjectIndexOptions,
7
+ ObjectIndexSearchOptions,
8
+ } from './objects.js';
package/objects.d.ts CHANGED
@@ -82,10 +82,7 @@ export declare class FuzzyObjectIndex<T> {
82
82
  get size(): number;
83
83
 
84
84
  /** Search for objects matching the query. */
85
- search(
86
- query: string,
87
- options?: ObjectIndexSearchOptions,
88
- ): Array<ObjectSearchResult<T>>;
85
+ search(query: string, options?: ObjectIndexSearchOptions): Array<ObjectSearchResult<T>>;
89
86
 
90
87
  /** Find the closest matching object, or null if no match. */
91
88
  closest(query: string, minScore?: number): T | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapid-fuzzy",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Rust-powered fuzzy search and string distance for JavaScript/TypeScript. 10-50x faster than fuse.js/leven.",
5
5
  "license": "MIT",
6
6
  "author": "derodero24",
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "./highlight": {
48
48
  "import": {
49
- "types": "./highlight.d.ts",
49
+ "types": "./highlight.d.mts",
50
50
  "default": "./highlight.mjs"
51
51
  },
52
52
  "require": {
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "./objects": {
58
58
  "import": {
59
- "types": "./objects.d.ts",
59
+ "types": "./objects.d.mts",
60
60
  "default": "./objects.mjs"
61
61
  },
62
62
  "require": {
@@ -76,7 +76,9 @@
76
76
  "browser.js",
77
77
  "highlight.js",
78
78
  "highlight.mjs",
79
- "highlight.d.ts"
79
+ "highlight.d.ts",
80
+ "highlight.d.mts",
81
+ "objects.d.mts"
80
82
  ],
81
83
  "napi": {
82
84
  "binaryName": "rapid-fuzzy",
@@ -101,6 +103,8 @@
101
103
  "postbuild": "node scripts/patch-binding.js",
102
104
  "build:debug": "napi build --manifest-path crates/core/Cargo.toml --platform --js index.js --dts index.d.ts --output-dir .",
103
105
  "build:wasm": "napi build --manifest-path crates/core/Cargo.toml --platform --release --js index.js --dts index.d.ts --output-dir . --target wasm32-wasip1-threads",
106
+ "postbuild:wasm": "node scripts/optimize-wasm.js",
107
+ "optimize:wasm": "node scripts/optimize-wasm.js",
104
108
  "artifacts": "napi artifacts",
105
109
  "prepublishOnly": "napi prepublish -t npm",
106
110
  "version": "napi version",
@@ -116,6 +120,7 @@
116
120
  "test:deno": "deno test --allow-read --allow-env --allow-net --node-modules-dir=auto e2e/wasm-deno.test.ts",
117
121
  "test:watch": "vitest watch",
118
122
  "bench": "vitest bench",
123
+ "bench:ci": "vitest bench __test__/distance.bench.ts __test__/similarity.bench.ts __test__/ratio.bench.ts __test__/batch.bench.ts __test__/search.bench.ts",
119
124
  "bench:readme": "npx tsx scripts/update-bench-readme.ts",
120
125
  "bench:charts": "npx tsx scripts/generate-bench-charts.ts",
121
126
  "publint": "publint",
@@ -125,13 +130,13 @@
125
130
  "prepare": "lefthook install"
126
131
  },
127
132
  "devDependencies": {
128
- "@biomejs/biome": "^2.4.6",
133
+ "@biomejs/biome": "^2.4.8",
129
134
  "@changesets/cli": "^2.30.0",
130
135
  "@codspeed/vitest-plugin": "^5.2.0",
131
- "@commitlint/cli": "^20.4.4",
132
- "@commitlint/config-conventional": "^20.4.4",
133
- "@emnapi/core": "^1.9.0",
134
- "@emnapi/runtime": "^1.9.0",
136
+ "@commitlint/cli": "^20.5.0",
137
+ "@commitlint/config-conventional": "^20.5.0",
138
+ "@emnapi/core": "^1.9.1",
139
+ "@emnapi/runtime": "^1.9.1",
135
140
  "@leeoniya/ufuzzy": "^1.0.19",
136
141
  "@napi-rs/cli": "^3.5.1",
137
142
  "@napi-rs/wasm-runtime": "^1.1.1",
@@ -141,30 +146,38 @@
141
146
  "@types/string-similarity": "^4.0.2",
142
147
  "@vitest/coverage-v8": "^4.1.0",
143
148
  "fastest-levenshtein": "^1.0.16",
149
+ "flexsearch": "^0.8.212",
144
150
  "fuse.js": "^7.1.0",
151
+ "fuzzball": "^2.2.3",
145
152
  "fuzzysort": "^3.1.0",
146
153
  "lefthook": "^2.1.4",
147
154
  "leven": "^4.1.0",
155
+ "minisearch": "^7.2.0",
148
156
  "publint": "^0.3.18",
149
157
  "string-similarity": "^4.0.4",
150
- "typescript": "^5.9.3",
158
+ "typescript": "^6.0.0",
151
159
  "vite": "^8.0.0",
152
160
  "vitest": "^4.1.0"
153
161
  },
154
162
  "pnpm": {
155
163
  "onlyBuiltDependencies": [
156
164
  "lefthook"
157
- ]
165
+ ],
166
+ "peerDependencyRules": {
167
+ "allowedVersions": {
168
+ "@codspeed/vitest-plugin>vite": "8"
169
+ }
170
+ }
158
171
  },
159
172
  "optionalDependencies": {
160
- "rapid-fuzzy-darwin-x64": "1.0.0",
161
- "rapid-fuzzy-darwin-arm64": "1.0.0",
162
- "rapid-fuzzy-linux-x64-gnu": "1.0.0",
163
- "rapid-fuzzy-linux-x64-musl": "1.0.0",
164
- "rapid-fuzzy-linux-arm64-gnu": "1.0.0",
165
- "rapid-fuzzy-linux-arm64-musl": "1.0.0",
166
- "rapid-fuzzy-win32-x64-msvc": "1.0.0",
167
- "rapid-fuzzy-win32-arm64-msvc": "1.0.0",
168
- "rapid-fuzzy-wasm32-wasi": "1.0.0"
173
+ "rapid-fuzzy-darwin-x64": "1.1.1",
174
+ "rapid-fuzzy-darwin-arm64": "1.1.1",
175
+ "rapid-fuzzy-linux-x64-gnu": "1.1.1",
176
+ "rapid-fuzzy-linux-x64-musl": "1.1.1",
177
+ "rapid-fuzzy-linux-arm64-gnu": "1.1.1",
178
+ "rapid-fuzzy-linux-arm64-musl": "1.1.1",
179
+ "rapid-fuzzy-win32-x64-msvc": "1.1.1",
180
+ "rapid-fuzzy-win32-arm64-msvc": "1.1.1",
181
+ "rapid-fuzzy-wasm32-wasi": "1.1.1"
169
182
  }
170
183
  }