rapid-fuzzy 0.6.0 → 1.1.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/README.md +61 -45
- package/index.d.ts +120 -5
- package/index.js +56 -52
- package/index.mjs +5 -0
- package/objects.d.ts +6 -9
- package/objects.js +7 -2
- package/objects.mjs +2 -0
- package/package.json +52 -17
package/README.md
CHANGED
|
@@ -10,16 +10,18 @@
|
|
|
10
10
|
|
|
11
11
|
Blazing-fast fuzzy search for JavaScript — powered by Rust, works everywhere.
|
|
12
12
|
|
|
13
|
-
<img src=".github/assets/demo.svg" alt="rapid-fuzzy demo — fuzzy search, query syntax, FuzzyIndex, and string distance" width="580" />
|
|
14
|
-
|
|
15
13
|
## Features
|
|
16
14
|
|
|
17
|
-
- **Fast**: Up to
|
|
15
|
+
- **Fast**: Up to 15,000x faster than fuse.js with FuzzyIndex (Rust + napi-rs)
|
|
18
16
|
- **Universal**: Works in Node.js (native), browsers (WASM), Deno, and Bun
|
|
19
17
|
- **Zero JS dependencies**: Pure Rust core with napi-rs bindings
|
|
20
18
|
- **Type-safe**: Full TypeScript support with auto-generated type definitions
|
|
21
19
|
- **Drop-in**: API compatible with popular fuzzy search libraries
|
|
22
20
|
|
|
21
|
+
## Playground
|
|
22
|
+
|
|
23
|
+
Try rapid-fuzzy in the browser — no installation required: **[Open Playground](https://derodero24.github.io/rapid-fuzzy/)**
|
|
24
|
+
|
|
23
25
|
## Quick Start
|
|
24
26
|
|
|
25
27
|
```typescript
|
|
@@ -29,7 +31,7 @@ const results = search('typscript', ['TypeScript', 'JavaScript', 'Python']);
|
|
|
29
31
|
// → [{ item: 'TypeScript', score: 0.85, index: 0 }, ...]
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
For repeated searches, use `FuzzyIndex` for up to
|
|
34
|
+
For repeated searches, use `FuzzyIndex` for up to 297x faster lookups:
|
|
33
35
|
|
|
34
36
|
```typescript
|
|
35
37
|
import { FuzzyIndex } from 'rapid-fuzzy';
|
|
@@ -49,9 +51,16 @@ pnpm add rapid-fuzzy
|
|
|
49
51
|
### Runtime-specific notes
|
|
50
52
|
|
|
51
53
|
- **Node.js** (>=20): Uses native bindings via napi-rs for best performance.
|
|
52
|
-
- **Browser / Deno / Bun**: Falls back to a WASM build automatically.
|
|
54
|
+
- **Browser / Deno / Bun**: Falls back to a WASM build automatically. The WASM binary is ~660 KB raw (~230 KB gzipped).
|
|
53
55
|
|
|
54
|
-
> **
|
|
56
|
+
> **Browser WASM requirement**: The WASM build uses `SharedArrayBuffer` for threading, which requires the following HTTP headers on your page:
|
|
57
|
+
> ```
|
|
58
|
+
> Cross-Origin-Opener-Policy: same-origin
|
|
59
|
+
> Cross-Origin-Embedder-Policy: require-corp
|
|
60
|
+
> ```
|
|
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
|
+
|
|
63
|
+
## API
|
|
55
64
|
|
|
56
65
|
### Fuzzy Search
|
|
57
66
|
|
|
@@ -70,9 +79,6 @@ const results = search('typscript', [
|
|
|
70
79
|
// With options: filter by minimum score and limit results
|
|
71
80
|
search('app', items, { maxResults: 5, minScore: 0.3 });
|
|
72
81
|
|
|
73
|
-
// Backward compatible: pass a number for maxResults
|
|
74
|
-
search('app', items, 5);
|
|
75
|
-
|
|
76
82
|
// Get matched character positions for highlighting
|
|
77
83
|
const [match] = search('hlo', ['hello world'], { includePositions: true });
|
|
78
84
|
// → { item: 'hello world', score: 0.75, index: 0, positions: [0, 2, 4] }
|
|
@@ -80,6 +86,9 @@ const [match] = search('hlo', ['hello world'], { includePositions: true });
|
|
|
80
86
|
// Case-sensitive matching (default: smart case)
|
|
81
87
|
search('Type', items, { isCaseSensitive: true });
|
|
82
88
|
|
|
89
|
+
// Return all items when query is empty (useful for filter-as-you-type UIs)
|
|
90
|
+
search('', items, { returnAllOnEmpty: true });
|
|
91
|
+
|
|
83
92
|
// Find the single best match
|
|
84
93
|
closest('tsc', ['TypeScript', 'JavaScript', 'Python']);
|
|
85
94
|
// → 'TypeScript'
|
|
@@ -92,11 +101,12 @@ closest('xyz', items, 0.5);
|
|
|
92
101
|
### String Distance
|
|
93
102
|
|
|
94
103
|
```typescript
|
|
95
|
-
import { levenshtein, jaroWinkler, sorensenDice } from 'rapid-fuzzy';
|
|
104
|
+
import { levenshtein, jaroWinkler, sorensenDice, hamming } from 'rapid-fuzzy';
|
|
96
105
|
|
|
97
106
|
levenshtein('kitten', 'sitting'); // 3
|
|
98
107
|
jaroWinkler('MARTHA', 'MARHTA'); // 0.961
|
|
99
108
|
sorensenDice('night', 'nacht'); // 0.25
|
|
109
|
+
hamming('karolin', 'kathrin'); // 3 (null if lengths differ)
|
|
100
110
|
```
|
|
101
111
|
|
|
102
112
|
### Query Syntax
|
|
@@ -153,12 +163,16 @@ For applications that search the same dataset repeatedly (autocomplete, file fin
|
|
|
153
163
|
```typescript
|
|
154
164
|
import { FuzzyIndex, FuzzyObjectIndex } from 'rapid-fuzzy';
|
|
155
165
|
|
|
156
|
-
// String search index — up to
|
|
166
|
+
// String search index — up to 297x faster than standalone search()
|
|
157
167
|
const index = new FuzzyIndex(['TypeScript', 'JavaScript', 'Python', ...]);
|
|
158
168
|
|
|
159
169
|
index.search('typscript', { maxResults: 5 });
|
|
160
170
|
index.closest('tsc');
|
|
161
171
|
|
|
172
|
+
// Index-only results (no string cloning — less GC pressure)
|
|
173
|
+
const hits = index.searchIndices('typscript', { maxResults: 5 });
|
|
174
|
+
// → [{ index: 0, score: 0.85, positions: [] }, ...]
|
|
175
|
+
|
|
162
176
|
// Mutate the index without rebuilding
|
|
163
177
|
index.add('Rust');
|
|
164
178
|
index.remove(2); // swap-remove by index
|
|
@@ -200,7 +214,8 @@ highlightRanges(item, positions);
|
|
|
200
214
|
// → [{ start: 0, end: 1, matched: true }, { start: 1, end: 2, matched: false }, ...]
|
|
201
215
|
```
|
|
202
216
|
|
|
203
|
-
|
|
217
|
+
<details>
|
|
218
|
+
<summary><strong>Token-Based Matching</strong></summary>
|
|
204
219
|
|
|
205
220
|
Order-independent and partial string matching, inspired by Python's [RapidFuzz](https://github.com/rapidfuzz/RapidFuzz):
|
|
206
221
|
|
|
@@ -227,7 +242,10 @@ weightedRatio('John Smith', 'Smith, John'); // 1.0
|
|
|
227
242
|
|
|
228
243
|
All token-based functions include `Batch` and `Many` variants (e.g., `tokenSortRatioBatch`, `tokenSortRatioMany`).
|
|
229
244
|
|
|
230
|
-
|
|
245
|
+
</details>
|
|
246
|
+
|
|
247
|
+
<details>
|
|
248
|
+
<summary><strong>Batch Operations</strong></summary>
|
|
231
249
|
|
|
232
250
|
All distance functions have `Batch` and `Many` variants that amortize FFI overhead:
|
|
233
251
|
|
|
@@ -245,15 +263,22 @@ levenshteinBatch([
|
|
|
245
263
|
// Compare one string against many candidates
|
|
246
264
|
levenshteinMany('kitten', ['sitting', 'kittens', 'kitchen']);
|
|
247
265
|
// → [3, 1, 2]
|
|
266
|
+
|
|
267
|
+
// With early-termination threshold (skip candidates that can't match)
|
|
268
|
+
levenshteinMany('kitten', candidates, 3); // maxDistance → returns 4 for exceeding
|
|
269
|
+
jaroWinklerMany('MARTHA', candidates, 0.8); // minSimilarity → returns 0.0 for below
|
|
248
270
|
```
|
|
249
271
|
|
|
250
272
|
> **Tip**: Prefer batch/many variants over calling single-pair functions in a loop — they are significantly faster for multiple comparisons.
|
|
251
273
|
|
|
274
|
+
</details>
|
|
275
|
+
|
|
252
276
|
## Choosing an Algorithm
|
|
253
277
|
|
|
254
278
|
| Use case | Recommended | Why |
|
|
255
279
|
|---|---|---|
|
|
256
280
|
| Typo detection / spell check | `levenshtein`, `damerauLevenshtein` | Counts edits; Damerau adds transposition support |
|
|
281
|
+
| Fixed-length comparison | `hamming` | Counts differing positions; only for equal-length strings |
|
|
257
282
|
| Name / address matching | `jaroWinkler`, `tokenSortRatio` | Prefix-weighted or order-independent matching |
|
|
258
283
|
| Document / text similarity | `sorensenDice` | Bigram-based; handles longer text well |
|
|
259
284
|
| Normalized comparison (0–1) | `normalizedLevenshtein` | Length-independent similarity score |
|
|
@@ -261,11 +286,11 @@ levenshteinMany('kitten', ['sitting', 'kittens', 'kitchen']);
|
|
|
261
286
|
| Substring / abbreviation matching | `partialRatio` | Finds best partial match within longer strings |
|
|
262
287
|
| Best-effort similarity | `weightedRatio` | Picks the best score across all methods automatically |
|
|
263
288
|
| Interactive fuzzy search | `search`, `closest` | Nucleo algorithm (same as Helix editor) |
|
|
264
|
-
| Repeated search on same data | `FuzzyIndex`, `FuzzyObjectIndex` | Persistent Rust-side index with incremental cache, up to
|
|
289
|
+
| Repeated search on same data | `FuzzyIndex`, `FuzzyObjectIndex` | Persistent Rust-side index with incremental cache, up to 297x faster |
|
|
265
290
|
|
|
266
291
|
**Return types:**
|
|
267
292
|
|
|
268
|
-
- `levenshtein`, `damerauLevenshtein` → integer (edit count)
|
|
293
|
+
- `levenshtein`, `damerauLevenshtein`, `hamming` → integer (edit/difference count; `hamming` returns `null` if lengths differ)
|
|
269
294
|
- `jaro`, `jaroWinkler`, `sorensenDice`, `normalizedLevenshtein` → float between 0.0 (no match) and 1.0 (identical)
|
|
270
295
|
- `tokenSortRatio`, `tokenSetRatio`, `partialRatio`, `weightedRatio` → float between 0.0 and 1.0
|
|
271
296
|
- `search` → array of `{ item, score, index, positions }` sorted by relevance (score: 0.0–1.0)
|
|
@@ -283,15 +308,16 @@ Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.
|
|
|
283
308
|
|
|
284
309
|
| Function | rapid-fuzzy | fastest-levenshtein | leven | string-similarity |
|
|
285
310
|
|---|---:|---:|---:|---:|
|
|
286
|
-
| Levenshtein |
|
|
287
|
-
| Normalized Levenshtein | **
|
|
288
|
-
| Sorensen-Dice | **
|
|
289
|
-
| Jaro-Winkler | **
|
|
290
|
-
| Damerau-Levenshtein | **116,
|
|
311
|
+
| Levenshtein | 545,338 ops/s | **741,195 ops/s** | 225,457 ops/s | — |
|
|
312
|
+
| Normalized Levenshtein | **514,446 ops/s** | — | — | — |
|
|
313
|
+
| Sorensen-Dice | **142,180 ops/s** | — | — | 56,729 ops/s |
|
|
314
|
+
| Jaro-Winkler | **505,762 ops/s** | — | — | — |
|
|
315
|
+
| Damerau-Levenshtein | **116,186 ops/s** | — | — | — |
|
|
316
|
+
| Hamming | **883,614 ops/s** | — | — | — |
|
|
291
317
|
|
|
292
318
|
</details>
|
|
293
319
|
|
|
294
|
-
> **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.
|
|
320
|
+
> **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.
|
|
295
321
|
|
|
296
322
|
### Search Performance
|
|
297
323
|
|
|
@@ -304,10 +330,9 @@ Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.
|
|
|
304
330
|
|
|
305
331
|
| Dataset size | rapid-fuzzy | rapid-fuzzy (indexed) | fuse.js | fuzzysort | uFuzzy |
|
|
306
332
|
|---|---:|---:|---:|---:|---:|
|
|
307
|
-
| Small (20 items) |
|
|
308
|
-
| Medium (1K items) | 6,
|
|
309
|
-
| Large (10K items) |
|
|
310
|
-
| XL (50K items) | — | **31,903 ops/s** | — | 5,916 ops/s | 1,292 ops/s |
|
|
333
|
+
| Small (20 items) | 279,509 ops/s | 395,932 ops/s | 118,443 ops/s | **1,661,273 ops/s** | 422,032 ops/s |
|
|
334
|
+
| Medium (1K items) | 6,274 ops/s | **77,271 ops/s** | 358 ops/s | 58,123 ops/s | 26,052 ops/s |
|
|
335
|
+
| Large (10K items) | 777 ops/s | **230,848 ops/s** | 15 ops/s | 25,315 ops/s | 4,663 ops/s |
|
|
311
336
|
|
|
312
337
|
</details>
|
|
313
338
|
|
|
@@ -315,31 +340,22 @@ Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.
|
|
|
315
340
|
|
|
316
341
|
| Dataset size | rapid-fuzzy | rapid-fuzzy (indexed) | fastest-levenshtein |
|
|
317
342
|
|---|---:|---:|---:|
|
|
318
|
-
| Medium (1K items) |
|
|
319
|
-
| Large (10K items) |
|
|
343
|
+
| Medium (1K items) | 7,690 ops/s | **906,274 ops/s** | 3,536 ops/s |
|
|
344
|
+
| Large (10K items) | 611 ops/s | **352,688 ops/s** | 620 ops/s |
|
|
320
345
|
|
|
321
|
-
> In indexed mode (`FuzzyIndex`), rapid-fuzzy is up to **
|
|
346
|
+
> In indexed mode (`FuzzyIndex`), rapid-fuzzy is up to **569x faster** than fastest-levenshtein for closest-match lookups.
|
|
322
347
|
|
|
323
|
-
###
|
|
348
|
+
### Key takeaways
|
|
324
349
|
|
|
325
|
-
- **vs fuse.js**: `FuzzyIndex` is **
|
|
326
|
-
- **Indexed mode**: `FuzzyIndex` keeps data on the Rust side with
|
|
327
|
-
- **vs fuzzysort**: `FuzzyIndex`
|
|
328
|
-
- **vs uFuzzy**: `FuzzyIndex` is **2.8x faster** at medium and **21x faster** at large datasets.
|
|
329
|
-
- **vs fastest-levenshtein**: With `FuzzyIndex`, closest-match is **145x faster** at 1K and **237x faster** at 10K.
|
|
330
|
-
|
|
331
|
-
Run benchmarks yourself:
|
|
332
|
-
|
|
333
|
-
```bash
|
|
334
|
-
pnpm run bench # JavaScript benchmarks
|
|
335
|
-
cargo bench # Rust internal benchmarks
|
|
336
|
-
```
|
|
350
|
+
- **vs fuse.js**: `FuzzyIndex` is **216x–15,390x faster** depending on dataset size. Even standalone `search()` is 18–52x faster.
|
|
351
|
+
- **Indexed mode**: `FuzzyIndex` keeps data on the Rust side with incremental caching — **297x faster** than standalone `search()` on large datasets, delivering sub-millisecond autocomplete.
|
|
352
|
+
- **vs fuzzysort / uFuzzy**: `FuzzyIndex` outperforms both on 1K+ datasets (up to 9.1x vs fuzzysort, 50x vs uFuzzy).
|
|
337
353
|
|
|
338
354
|
## Why rapid-fuzzy?
|
|
339
355
|
|
|
340
356
|
| | rapid-fuzzy | fuse.js | fastest-levenshtein | fuzzysort | uFuzzy |
|
|
341
357
|
|---|:---:|:---:|:---:|:---:|:---:|
|
|
342
|
-
| **Algorithms** |
|
|
358
|
+
| **Algorithms** | 10 (Levenshtein, Hamming, Jaro, Dice, …) | Bitap | Levenshtein | Substring | Regex-based |
|
|
343
359
|
| **Runtime** | Rust native + WASM | Pure JS | Pure JS | Pure JS | Pure JS |
|
|
344
360
|
| **Object search** | ✅ weighted keys | ✅ | — | ✅ | — |
|
|
345
361
|
| **Persistent index** | ✅ FuzzyIndex / FuzzyObjectIndex | — | — | ✅ prepared targets | — |
|
|
@@ -351,7 +367,7 @@ cargo bench # Rust internal benchmarks
|
|
|
351
367
|
| **Highlight utility** | ✅ | — | — | ✅ | ✅ |
|
|
352
368
|
| **Batch API** | ✅ | — | — | — | — |
|
|
353
369
|
| **Node.js native** | ✅ napi-rs | — | — | — | — |
|
|
354
|
-
| **Browser** | ✅ WASM | ✅ | ✅ | ✅ | ✅ |
|
|
370
|
+
| **Browser** | ✅ WASM (~230 KB gzipped) | ✅ | ✅ | ✅ | ✅ |
|
|
355
371
|
| **TypeScript** | ✅ full | ✅ full | ✅ | ✅ | ✅ |
|
|
356
372
|
|
|
357
373
|
## Migration Guides
|
|
@@ -359,9 +375,9 @@ cargo bench # Rust internal benchmarks
|
|
|
359
375
|
Switching from another library? These guides provide API mapping tables, code examples, and performance comparisons:
|
|
360
376
|
|
|
361
377
|
- [**From string-similarity**](docs/migration/from-string-similarity.md) — Same Dice coefficient algorithm, now maintained and faster
|
|
362
|
-
- [**From fuse.js**](docs/migration/from-fuse-js.md) — Up to
|
|
378
|
+
- [**From fuse.js**](docs/migration/from-fuse-js.md) — Up to 15,000x faster fuzzy search with FuzzyIndex
|
|
363
379
|
- [**From leven / fastest-levenshtein**](docs/migration/from-leven.md) — Multi-algorithm upgrade with batch APIs
|
|
364
|
-
- [**From fuzzysort**](docs/migration/from-fuzzysort.md) — Richer matching with query syntax and
|
|
380
|
+
- [**From fuzzysort**](docs/migration/from-fuzzysort.md) — Richer matching with query syntax and 10 distance algorithms
|
|
365
381
|
- [**From uFuzzy**](docs/migration/from-ufuzzy.md) — Weighted object search, batch APIs, and persistent indexes
|
|
366
382
|
|
|
367
383
|
## License
|
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. */
|
|
@@ -41,6 +49,21 @@ export declare class FuzzyIndex {
|
|
|
41
49
|
remove(index: number): boolean
|
|
42
50
|
/** Free the internal data. After calling this, the index is empty. */
|
|
43
51
|
destroy(): void
|
|
52
|
+
/**
|
|
53
|
+
* Serialize the index to a compact binary format.
|
|
54
|
+
*
|
|
55
|
+
* The returned Buffer can be written to disk, stored in IndexedDB,
|
|
56
|
+
* or transferred over the network. Use `FuzzyIndex.deserialize()` to
|
|
57
|
+
* reconstruct the index.
|
|
58
|
+
*/
|
|
59
|
+
serialize(): Buffer
|
|
60
|
+
/**
|
|
61
|
+
* Reconstruct a FuzzyIndex from a previously serialized Buffer.
|
|
62
|
+
*
|
|
63
|
+
* Pre-computes Utf32String and character masks from the stored items,
|
|
64
|
+
* so the returned index is immediately ready for searching.
|
|
65
|
+
*/
|
|
66
|
+
static deserialize(data: Buffer): FuzzyIndex
|
|
44
67
|
}
|
|
45
68
|
|
|
46
69
|
/**
|
|
@@ -75,12 +98,14 @@ export declare class KeyedFuzzyIndex {
|
|
|
75
98
|
* Add a single item to the index.
|
|
76
99
|
*
|
|
77
100
|
* `key_values` must have the same length as the number of keys.
|
|
101
|
+
* Throws if the length does not match.
|
|
78
102
|
*/
|
|
79
103
|
add(keyValues: Array<string>): void
|
|
80
104
|
/**
|
|
81
105
|
* Add multiple items to the index at once.
|
|
82
106
|
*
|
|
83
107
|
* Each element of `items_key_values` is an array of key values for one item.
|
|
108
|
+
* Throws if any element has the wrong number of key values.
|
|
84
109
|
*/
|
|
85
110
|
addMany(itemsKeyValues: Array<Array<string>>): void
|
|
86
111
|
/**
|
|
@@ -120,8 +145,62 @@ export declare function damerauLevenshteinBatch(pairs: Array<Array<string>>): Ar
|
|
|
120
145
|
* Compute the Damerau-Levenshtein distance from one reference string to many candidates.
|
|
121
146
|
*
|
|
122
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.
|
|
123
159
|
*/
|
|
124
|
-
export declare function
|
|
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).
|
|
178
|
+
*/
|
|
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
|
+
}
|
|
125
204
|
|
|
126
205
|
/**
|
|
127
206
|
* Compute the Jaro similarity between two strings.
|
|
@@ -141,8 +220,10 @@ export declare function jaroBatch(pairs: Array<Array<string>>): Array<number>
|
|
|
141
220
|
* Compute the Jaro similarity from one reference string to many candidates.
|
|
142
221
|
*
|
|
143
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).
|
|
144
225
|
*/
|
|
145
|
-
export declare function jaroMany(reference: string, candidates: Array<string
|
|
226
|
+
export declare function jaroMany(reference: string, candidates: Array<string>, minSimilarity?: number | undefined | null): Array<number>
|
|
146
227
|
|
|
147
228
|
/**
|
|
148
229
|
* Compute the Jaro-Winkler similarity between two strings.
|
|
@@ -163,8 +244,10 @@ export declare function jaroWinklerBatch(pairs: Array<Array<string>>): Array<num
|
|
|
163
244
|
* Compute the Jaro-Winkler similarity from one reference string to many candidates.
|
|
164
245
|
*
|
|
165
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).
|
|
166
249
|
*/
|
|
167
|
-
export declare function jaroWinklerMany(reference: string, candidates: Array<string
|
|
250
|
+
export declare function jaroWinklerMany(reference: string, candidates: Array<string>, minSimilarity?: number | undefined | null): Array<number>
|
|
168
251
|
|
|
169
252
|
/** A single result from multi-key fuzzy search. */
|
|
170
253
|
export interface KeySearchResult {
|
|
@@ -200,8 +283,26 @@ export declare function levenshteinBatch(pairs: Array<Array<string>>): Array<num
|
|
|
200
283
|
* Compute the Levenshtein distance from one reference string to many candidates.
|
|
201
284
|
*
|
|
202
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).
|
|
288
|
+
*/
|
|
289
|
+
export declare function levenshteinMany(reference: string, candidates: Array<string>, maxDistance?: number | undefined | null): Array<number>
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Classification of how a query matched an item.
|
|
293
|
+
*
|
|
294
|
+
* Derived from the matched character positions:
|
|
295
|
+
* - **Exact**: all positions consecutive from index 0, covering every character in the item.
|
|
296
|
+
* - **Prefix**: all positions consecutive from index 0, but the item is longer.
|
|
297
|
+
* - **Contains**: all positions consecutive (a substring match), not starting at 0.
|
|
298
|
+
* - **Fuzzy**: positions have gaps (character-level fuzzy match).
|
|
203
299
|
*/
|
|
204
|
-
export declare
|
|
300
|
+
export declare const enum MatchType {
|
|
301
|
+
Exact = 'Exact',
|
|
302
|
+
Prefix = 'Prefix',
|
|
303
|
+
Contains = 'Contains',
|
|
304
|
+
Fuzzy = 'Fuzzy'
|
|
305
|
+
}
|
|
205
306
|
|
|
206
307
|
/**
|
|
207
308
|
* Compute the normalized Levenshtein similarity between two strings.
|
|
@@ -221,8 +322,10 @@ export declare function normalizedLevenshteinBatch(pairs: Array<Array<string>>):
|
|
|
221
322
|
* Compute the normalized Levenshtein similarity from one reference string to many candidates.
|
|
222
323
|
*
|
|
223
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).
|
|
224
327
|
*/
|
|
225
|
-
export declare function normalizedLevenshteinMany(reference: string, candidates: Array<string
|
|
328
|
+
export declare function normalizedLevenshteinMany(reference: string, candidates: Array<string>, minSimilarity?: number | undefined | null): Array<number>
|
|
226
329
|
|
|
227
330
|
/**
|
|
228
331
|
* Compute the partial ratio between two strings.
|
|
@@ -285,6 +388,12 @@ export interface SearchOptions {
|
|
|
285
388
|
* (case-insensitive unless the query contains uppercase characters).
|
|
286
389
|
*/
|
|
287
390
|
isCaseSensitive?: boolean
|
|
391
|
+
/**
|
|
392
|
+
* If true, return all items when the query is empty (or whitespace-only).
|
|
393
|
+
* Useful for filter-as-you-type UIs where the full list should appear
|
|
394
|
+
* before the user starts typing. Default is false.
|
|
395
|
+
*/
|
|
396
|
+
returnAllOnEmpty?: boolean
|
|
288
397
|
}
|
|
289
398
|
|
|
290
399
|
/** A single fuzzy search result with the matched item and its score. */
|
|
@@ -300,6 +409,12 @@ export interface SearchResult {
|
|
|
300
409
|
* Empty unless `includePositions` is set to true in SearchOptions.
|
|
301
410
|
*/
|
|
302
411
|
positions: Array<number>
|
|
412
|
+
/**
|
|
413
|
+
* How the query matched this item (Exact, Prefix, Contains, or Fuzzy).
|
|
414
|
+
* Only present when `includePositions` is set to true in SearchOptions.
|
|
415
|
+
* Derived from positions at zero additional cost.
|
|
416
|
+
*/
|
|
417
|
+
matchType?: MatchType
|
|
303
418
|
}
|
|
304
419
|
|
|
305
420
|
/**
|
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 !== '
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
80
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
96
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
117
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
133
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
150
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
166
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
185
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
201
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
217
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
237
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
253
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
274
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
290
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
308
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
324
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
342
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
358
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
376
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
392
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
410
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
426
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
443
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
459
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
479
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
495
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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 !== '
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected
|
|
511
|
+
if (bindingPackageVersion !== '1.1.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.1.0 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
|
|
@@ -591,6 +594,7 @@ module.exports.jaroWinklerMany = nativeBinding.jaroWinklerMany
|
|
|
591
594
|
module.exports.levenshtein = nativeBinding.levenshtein
|
|
592
595
|
module.exports.levenshteinBatch = nativeBinding.levenshteinBatch
|
|
593
596
|
module.exports.levenshteinMany = nativeBinding.levenshteinMany
|
|
597
|
+
module.exports.MatchType = nativeBinding.MatchType
|
|
594
598
|
module.exports.normalizedLevenshtein = nativeBinding.normalizedLevenshtein
|
|
595
599
|
module.exports.normalizedLevenshteinBatch = nativeBinding.normalizedLevenshteinBatch
|
|
596
600
|
module.exports.normalizedLevenshteinMany = nativeBinding.normalizedLevenshteinMany
|
package/index.mjs
CHANGED
|
@@ -5,11 +5,16 @@ const binding = require('./index.js');
|
|
|
5
5
|
|
|
6
6
|
export const {
|
|
7
7
|
FuzzyIndex,
|
|
8
|
+
KeyedFuzzyIndex,
|
|
9
|
+
MatchType,
|
|
8
10
|
closest,
|
|
9
11
|
searchKeys,
|
|
10
12
|
damerauLevenshtein,
|
|
11
13
|
damerauLevenshteinBatch,
|
|
12
14
|
damerauLevenshteinMany,
|
|
15
|
+
hamming,
|
|
16
|
+
hammingBatch,
|
|
17
|
+
hammingMany,
|
|
13
18
|
jaro,
|
|
14
19
|
jaroBatch,
|
|
15
20
|
jaroMany,
|
package/objects.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export interface KeyConfig {
|
|
|
5
5
|
weight?: number;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Options for searchObjects(). Extends SearchOptions with key configuration.
|
|
10
|
+
* Note: `includePositions` has no effect for multi-key search.
|
|
11
|
+
*/
|
|
8
12
|
export interface ObjectSearchOptions extends SearchOptions {
|
|
9
13
|
keys: Array<string | KeyConfig>;
|
|
10
14
|
}
|
|
@@ -14,11 +18,6 @@ export interface ObjectSearchResult<T> {
|
|
|
14
18
|
index: number;
|
|
15
19
|
score: number;
|
|
16
20
|
keyScores: Array<number>;
|
|
17
|
-
/**
|
|
18
|
-
* Indices of matched characters in the best-matching key string.
|
|
19
|
-
* Empty unless `includePositions` is set to true in ObjectSearchOptions.
|
|
20
|
-
*/
|
|
21
|
-
positions: Array<number>;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
/**
|
|
@@ -54,6 +53,7 @@ export interface ObjectIndexSearchOptions {
|
|
|
54
53
|
maxResults?: number;
|
|
55
54
|
minScore?: number;
|
|
56
55
|
isCaseSensitive?: boolean;
|
|
56
|
+
returnAllOnEmpty?: boolean;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
@@ -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<Omit<ObjectSearchResult<T>, 'positions'>>;
|
|
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/objects.js
CHANGED
|
@@ -31,9 +31,12 @@ function getNestedValue(obj, path) {
|
|
|
31
31
|
* @param {number} [options.maxResults] - Maximum results to return.
|
|
32
32
|
* @param {number} [options.minScore] - Minimum score threshold.
|
|
33
33
|
* @param {boolean} [options.isCaseSensitive] - Enable case-sensitive matching.
|
|
34
|
-
* @returns {Array<{ item: T; index: number; score: number; keyScores: number[]
|
|
34
|
+
* @returns {Array<{ item: T; index: number; score: number; keyScores: number[] }>}
|
|
35
35
|
*/
|
|
36
36
|
function searchObjects(query, items, options) {
|
|
37
|
+
if (!options?.keys?.length) {
|
|
38
|
+
throw new TypeError('options.keys must be a non-empty array');
|
|
39
|
+
}
|
|
37
40
|
const { keys, ...searchOpts } = options;
|
|
38
41
|
|
|
39
42
|
const normalizedKeys = keys.map((k) =>
|
|
@@ -52,7 +55,6 @@ function searchObjects(query, items, options) {
|
|
|
52
55
|
index: r.index,
|
|
53
56
|
score: r.score,
|
|
54
57
|
keyScores: r.keyScores,
|
|
55
|
-
positions: r.positions ?? [],
|
|
56
58
|
}));
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -78,6 +80,9 @@ class FuzzyObjectIndex {
|
|
|
78
80
|
* @param {Array<string | { name: string; weight?: number }>} options.keys - Keys to search.
|
|
79
81
|
*/
|
|
80
82
|
constructor(items, options) {
|
|
83
|
+
if (!options?.keys?.length) {
|
|
84
|
+
throw new TypeError('options.keys must be a non-empty array');
|
|
85
|
+
}
|
|
81
86
|
this.#keys = options.keys.map((k) =>
|
|
82
87
|
typeof k === 'string' ? { name: k, weight: 1.0 } : { name: k.name, weight: k.weight ?? 1.0 },
|
|
83
88
|
);
|
package/objects.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rapid-fuzzy",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|
|
@@ -12,11 +12,15 @@
|
|
|
12
12
|
"keywords": [
|
|
13
13
|
"fuzzy",
|
|
14
14
|
"fuzzy-search",
|
|
15
|
+
"fuzzy-matching",
|
|
15
16
|
"string-distance",
|
|
17
|
+
"string-similarity",
|
|
16
18
|
"levenshtein",
|
|
17
19
|
"jaro-winkler",
|
|
20
|
+
"hamming",
|
|
21
|
+
"damerau-levenshtein",
|
|
18
22
|
"rust",
|
|
19
|
-
"napi",
|
|
23
|
+
"napi-rs",
|
|
20
24
|
"wasm",
|
|
21
25
|
"typescript",
|
|
22
26
|
"search",
|
|
@@ -39,6 +43,26 @@
|
|
|
39
43
|
"default": "./index.js"
|
|
40
44
|
},
|
|
41
45
|
"browser": "./browser.js"
|
|
46
|
+
},
|
|
47
|
+
"./highlight": {
|
|
48
|
+
"import": {
|
|
49
|
+
"types": "./highlight.d.ts",
|
|
50
|
+
"default": "./highlight.mjs"
|
|
51
|
+
},
|
|
52
|
+
"require": {
|
|
53
|
+
"types": "./highlight.d.ts",
|
|
54
|
+
"default": "./highlight.js"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"./objects": {
|
|
58
|
+
"import": {
|
|
59
|
+
"types": "./objects.d.ts",
|
|
60
|
+
"default": "./objects.mjs"
|
|
61
|
+
},
|
|
62
|
+
"require": {
|
|
63
|
+
"types": "./objects.d.ts",
|
|
64
|
+
"default": "./objects.js"
|
|
65
|
+
}
|
|
42
66
|
}
|
|
43
67
|
},
|
|
44
68
|
"files": [
|
|
@@ -47,6 +71,7 @@
|
|
|
47
71
|
"index.d.ts",
|
|
48
72
|
"index.d.mts",
|
|
49
73
|
"objects.js",
|
|
74
|
+
"objects.mjs",
|
|
50
75
|
"objects.d.ts",
|
|
51
76
|
"browser.js",
|
|
52
77
|
"highlight.js",
|
|
@@ -76,6 +101,8 @@
|
|
|
76
101
|
"postbuild": "node scripts/patch-binding.js",
|
|
77
102
|
"build:debug": "napi build --manifest-path crates/core/Cargo.toml --platform --js index.js --dts index.d.ts --output-dir .",
|
|
78
103
|
"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",
|
|
104
|
+
"postbuild:wasm": "node scripts/optimize-wasm.js",
|
|
105
|
+
"optimize:wasm": "node scripts/optimize-wasm.js",
|
|
79
106
|
"artifacts": "napi artifacts",
|
|
80
107
|
"prepublishOnly": "napi prepublish -t npm",
|
|
81
108
|
"version": "napi version",
|
|
@@ -100,13 +127,13 @@
|
|
|
100
127
|
"prepare": "lefthook install"
|
|
101
128
|
},
|
|
102
129
|
"devDependencies": {
|
|
103
|
-
"@biomejs/biome": "^2.4.
|
|
130
|
+
"@biomejs/biome": "^2.4.8",
|
|
104
131
|
"@changesets/cli": "^2.30.0",
|
|
105
132
|
"@codspeed/vitest-plugin": "^5.2.0",
|
|
106
|
-
"@commitlint/cli": "^20.
|
|
107
|
-
"@commitlint/config-conventional": "^20.
|
|
108
|
-
"@emnapi/core": "^1.9.
|
|
109
|
-
"@emnapi/runtime": "^1.9.
|
|
133
|
+
"@commitlint/cli": "^20.5.0",
|
|
134
|
+
"@commitlint/config-conventional": "^20.5.0",
|
|
135
|
+
"@emnapi/core": "^1.9.1",
|
|
136
|
+
"@emnapi/runtime": "^1.9.1",
|
|
110
137
|
"@leeoniya/ufuzzy": "^1.0.19",
|
|
111
138
|
"@napi-rs/cli": "^3.5.1",
|
|
112
139
|
"@napi-rs/wasm-runtime": "^1.1.1",
|
|
@@ -116,10 +143,13 @@
|
|
|
116
143
|
"@types/string-similarity": "^4.0.2",
|
|
117
144
|
"@vitest/coverage-v8": "^4.1.0",
|
|
118
145
|
"fastest-levenshtein": "^1.0.16",
|
|
146
|
+
"flexsearch": "^0.8.212",
|
|
119
147
|
"fuse.js": "^7.1.0",
|
|
148
|
+
"fuzzball": "^2.2.3",
|
|
120
149
|
"fuzzysort": "^3.1.0",
|
|
121
150
|
"lefthook": "^2.1.4",
|
|
122
151
|
"leven": "^4.1.0",
|
|
152
|
+
"minisearch": "^7.2.0",
|
|
123
153
|
"publint": "^0.3.18",
|
|
124
154
|
"string-similarity": "^4.0.4",
|
|
125
155
|
"typescript": "^5.9.3",
|
|
@@ -129,17 +159,22 @@
|
|
|
129
159
|
"pnpm": {
|
|
130
160
|
"onlyBuiltDependencies": [
|
|
131
161
|
"lefthook"
|
|
132
|
-
]
|
|
162
|
+
],
|
|
163
|
+
"peerDependencyRules": {
|
|
164
|
+
"allowedVersions": {
|
|
165
|
+
"@codspeed/vitest-plugin>vite": "8"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
133
168
|
},
|
|
134
169
|
"optionalDependencies": {
|
|
135
|
-
"rapid-fuzzy-darwin-x64": "
|
|
136
|
-
"rapid-fuzzy-darwin-arm64": "
|
|
137
|
-
"rapid-fuzzy-linux-x64-gnu": "
|
|
138
|
-
"rapid-fuzzy-linux-x64-musl": "
|
|
139
|
-
"rapid-fuzzy-linux-arm64-gnu": "
|
|
140
|
-
"rapid-fuzzy-linux-arm64-musl": "
|
|
141
|
-
"rapid-fuzzy-win32-x64-msvc": "
|
|
142
|
-
"rapid-fuzzy-win32-arm64-msvc": "
|
|
143
|
-
"rapid-fuzzy-wasm32-wasi": "
|
|
170
|
+
"rapid-fuzzy-darwin-x64": "1.1.0",
|
|
171
|
+
"rapid-fuzzy-darwin-arm64": "1.1.0",
|
|
172
|
+
"rapid-fuzzy-linux-x64-gnu": "1.1.0",
|
|
173
|
+
"rapid-fuzzy-linux-x64-musl": "1.1.0",
|
|
174
|
+
"rapid-fuzzy-linux-arm64-gnu": "1.1.0",
|
|
175
|
+
"rapid-fuzzy-linux-arm64-musl": "1.1.0",
|
|
176
|
+
"rapid-fuzzy-win32-x64-msvc": "1.1.0",
|
|
177
|
+
"rapid-fuzzy-win32-arm64-msvc": "1.1.0",
|
|
178
|
+
"rapid-fuzzy-wasm32-wasi": "1.1.0"
|
|
144
179
|
}
|
|
145
180
|
}
|