rapid-fuzzy 0.5.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -84
- package/index.d.ts +45 -0
- package/index.js +53 -52
- package/index.mjs +2 -0
- package/objects.d.ts +6 -6
- package/objects.js +7 -2
- package/objects.mjs +2 -0
- package/package.json +37 -11
package/README.md
CHANGED
|
@@ -8,18 +8,38 @@
|
|
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
|
9
9
|
[](https://nodejs.org/)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
> **Status**: Early release (v0.x). API may change between minor versions.
|
|
11
|
+
Blazing-fast fuzzy search for JavaScript — powered by Rust, works everywhere.
|
|
14
12
|
|
|
15
13
|
## Features
|
|
16
14
|
|
|
17
|
-
- **Fast**: Up to
|
|
15
|
+
- **Fast**: Up to 7,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
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { search } from 'rapid-fuzzy';
|
|
29
|
+
|
|
30
|
+
const results = search('typscript', ['TypeScript', 'JavaScript', 'Python']);
|
|
31
|
+
// → [{ item: 'TypeScript', score: 0.85, index: 0 }, ...]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For repeated searches, use `FuzzyIndex` for up to 165x faster lookups:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { FuzzyIndex } from 'rapid-fuzzy';
|
|
38
|
+
|
|
39
|
+
const index = new FuzzyIndex(['TypeScript', 'JavaScript', 'Python', ...]);
|
|
40
|
+
index.search('typscript'); // sub-millisecond with incremental cache
|
|
41
|
+
```
|
|
42
|
+
|
|
23
43
|
## Installation
|
|
24
44
|
|
|
25
45
|
```bash
|
|
@@ -31,19 +51,16 @@ pnpm add rapid-fuzzy
|
|
|
31
51
|
### Runtime-specific notes
|
|
32
52
|
|
|
33
53
|
- **Node.js** (>=20): Uses native bindings via napi-rs for best performance.
|
|
34
|
-
- **Browser / Deno / Bun**: Falls back to a WASM build automatically.
|
|
35
|
-
|
|
36
|
-
## Usage
|
|
54
|
+
- **Browser / Deno / Bun**: Falls back to a WASM build automatically. The WASM binary is ~607 KB raw (~200 KB gzipped).
|
|
37
55
|
|
|
38
|
-
|
|
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.
|
|
39
62
|
|
|
40
|
-
|
|
41
|
-
import { levenshtein, jaroWinkler, sorensenDice } from 'rapid-fuzzy';
|
|
42
|
-
|
|
43
|
-
levenshtein('kitten', 'sitting'); // 3
|
|
44
|
-
jaroWinkler('MARTHA', 'MARHTA'); // 0.961
|
|
45
|
-
sorensenDice('night', 'nacht'); // 0.25
|
|
46
|
-
```
|
|
63
|
+
## API
|
|
47
64
|
|
|
48
65
|
### Fuzzy Search
|
|
49
66
|
|
|
@@ -62,9 +79,6 @@ const results = search('typscript', [
|
|
|
62
79
|
// With options: filter by minimum score and limit results
|
|
63
80
|
search('app', items, { maxResults: 5, minScore: 0.3 });
|
|
64
81
|
|
|
65
|
-
// Backward compatible: pass a number for maxResults
|
|
66
|
-
search('app', items, 5);
|
|
67
|
-
|
|
68
82
|
// Get matched character positions for highlighting
|
|
69
83
|
const [match] = search('hlo', ['hello world'], { includePositions: true });
|
|
70
84
|
// → { item: 'hello world', score: 0.75, index: 0, positions: [0, 2, 4] }
|
|
@@ -81,6 +95,32 @@ closest('xyz', items, 0.5);
|
|
|
81
95
|
// → null
|
|
82
96
|
```
|
|
83
97
|
|
|
98
|
+
### String Distance
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { levenshtein, jaroWinkler, sorensenDice } from 'rapid-fuzzy';
|
|
102
|
+
|
|
103
|
+
levenshtein('kitten', 'sitting'); // 3
|
|
104
|
+
jaroWinkler('MARTHA', 'MARHTA'); // 0.961
|
|
105
|
+
sorensenDice('night', 'nacht'); // 0.25
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Query Syntax
|
|
109
|
+
|
|
110
|
+
Queries support extended syntax powered by the [nucleo](https://github.com/helix-editor/nucleo) pattern parser:
|
|
111
|
+
|
|
112
|
+
| Pattern | Match type | Example |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| `foo bar` | AND (order-independent) | `john smith` matches "Smith, John" |
|
|
115
|
+
| `!term` | Exclude | `apple !pie` excludes "apple pie" |
|
|
116
|
+
| `^term` | Starts with | `^app` matches "apple" but not "pineapple" |
|
|
117
|
+
| `term$` | Ends with | `pie$` matches "apple pie" |
|
|
118
|
+
| `'term` | Exact substring | `'pie` matches "pie" literally |
|
|
119
|
+
|
|
120
|
+
Diacritics are handled automatically — `cafe` matches `café`, `uber` matches `über`, and `naive` matches `naïve` with no configuration needed.
|
|
121
|
+
|
|
122
|
+
> **Note**: These patterns apply to all search functions: `search()`, `closest()`, `FuzzyIndex.search()`, `FuzzyObjectIndex.search()`, and `searchObjects()`. They do **not** apply to distance functions (`levenshtein`, `jaro`, etc.).
|
|
123
|
+
|
|
84
124
|
### Object Search
|
|
85
125
|
|
|
86
126
|
Search across object properties with weighted keys — a drop-in replacement for fuse.js's `keys` option:
|
|
@@ -119,7 +159,7 @@ For applications that search the same dataset repeatedly (autocomplete, file fin
|
|
|
119
159
|
```typescript
|
|
120
160
|
import { FuzzyIndex, FuzzyObjectIndex } from 'rapid-fuzzy';
|
|
121
161
|
|
|
122
|
-
// String search index — up to
|
|
162
|
+
// String search index — up to 165x faster than standalone search()
|
|
123
163
|
const index = new FuzzyIndex(['TypeScript', 'JavaScript', 'Python', ...]);
|
|
124
164
|
|
|
125
165
|
index.search('typscript', { maxResults: 5 });
|
|
@@ -166,7 +206,8 @@ highlightRanges(item, positions);
|
|
|
166
206
|
// → [{ start: 0, end: 1, matched: true }, { start: 1, end: 2, matched: false }, ...]
|
|
167
207
|
```
|
|
168
208
|
|
|
169
|
-
|
|
209
|
+
<details>
|
|
210
|
+
<summary><strong>Token-Based Matching</strong></summary>
|
|
170
211
|
|
|
171
212
|
Order-independent and partial string matching, inspired by Python's [RapidFuzz](https://github.com/rapidfuzz/RapidFuzz):
|
|
172
213
|
|
|
@@ -193,7 +234,10 @@ weightedRatio('John Smith', 'Smith, John'); // 1.0
|
|
|
193
234
|
|
|
194
235
|
All token-based functions include `Batch` and `Many` variants (e.g., `tokenSortRatioBatch`, `tokenSortRatioMany`).
|
|
195
236
|
|
|
196
|
-
|
|
237
|
+
</details>
|
|
238
|
+
|
|
239
|
+
<details>
|
|
240
|
+
<summary><strong>Batch Operations</strong></summary>
|
|
197
241
|
|
|
198
242
|
All distance functions have `Batch` and `Many` variants that amortize FFI overhead:
|
|
199
243
|
|
|
@@ -215,6 +259,29 @@ levenshteinMany('kitten', ['sitting', 'kittens', 'kitchen']);
|
|
|
215
259
|
|
|
216
260
|
> **Tip**: Prefer batch/many variants over calling single-pair functions in a loop — they are significantly faster for multiple comparisons.
|
|
217
261
|
|
|
262
|
+
</details>
|
|
263
|
+
|
|
264
|
+
## Choosing an Algorithm
|
|
265
|
+
|
|
266
|
+
| Use case | Recommended | Why |
|
|
267
|
+
|---|---|---|
|
|
268
|
+
| Typo detection / spell check | `levenshtein`, `damerauLevenshtein` | Counts edits; Damerau adds transposition support |
|
|
269
|
+
| Name / address matching | `jaroWinkler`, `tokenSortRatio` | Prefix-weighted or order-independent matching |
|
|
270
|
+
| Document / text similarity | `sorensenDice` | Bigram-based; handles longer text well |
|
|
271
|
+
| Normalized comparison (0–1) | `normalizedLevenshtein` | Length-independent similarity score |
|
|
272
|
+
| Reordered words / messy data | `tokenSortRatio`, `tokenSetRatio` | Handles word order differences and extra tokens |
|
|
273
|
+
| Substring / abbreviation matching | `partialRatio` | Finds best partial match within longer strings |
|
|
274
|
+
| Best-effort similarity | `weightedRatio` | Picks the best score across all methods automatically |
|
|
275
|
+
| 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 |
|
|
277
|
+
|
|
278
|
+
**Return types:**
|
|
279
|
+
|
|
280
|
+
- `levenshtein`, `damerauLevenshtein` → integer (edit count)
|
|
281
|
+
- `jaro`, `jaroWinkler`, `sorensenDice`, `normalizedLevenshtein` → float between 0.0 (no match) and 1.0 (identical)
|
|
282
|
+
- `tokenSortRatio`, `tokenSetRatio`, `partialRatio`, `weightedRatio` → float between 0.0 and 1.0
|
|
283
|
+
- `search` → array of `{ item, score, index, positions }` sorted by relevance (score: 0.0–1.0)
|
|
284
|
+
|
|
218
285
|
## Benchmarks
|
|
219
286
|
|
|
220
287
|
Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.dev/guide/features.html#benchmarking). Each benchmark processes 6 realistic string pairs of varying length and similarity.
|
|
@@ -228,98 +295,76 @@ Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.
|
|
|
228
295
|
|
|
229
296
|
| Function | rapid-fuzzy | fastest-levenshtein | leven | string-similarity |
|
|
230
297
|
|---|---:|---:|---:|---:|
|
|
231
|
-
| Levenshtein |
|
|
232
|
-
| Normalized Levenshtein | **
|
|
233
|
-
| Sorensen-Dice | **
|
|
234
|
-
| Jaro-Winkler | **
|
|
235
|
-
| Damerau-Levenshtein | **
|
|
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** | — | — | — |
|
|
236
303
|
|
|
237
304
|
</details>
|
|
238
305
|
|
|
239
|
-
> **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.
|
|
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.
|
|
240
307
|
|
|
241
308
|
### Search Performance
|
|
242
309
|
|
|
243
|
-
<img src=".github/assets/bench-search.svg" alt="Search performance chart — rapid-fuzzy vs fuse.js vs fuzzysort" width="680" />
|
|
310
|
+
<img src=".github/assets/bench-search.svg" alt="Search performance chart — rapid-fuzzy vs fuse.js vs fuzzysort vs uFuzzy" width="680" />
|
|
311
|
+
|
|
312
|
+
> Both `rapid-fuzzy` columns below show the same library: standalone `search()` vs `FuzzyIndex` (indexed mode for repeated searches).
|
|
244
313
|
|
|
245
314
|
<details>
|
|
246
315
|
<summary>Raw numbers</summary>
|
|
247
316
|
|
|
248
|
-
| Dataset size | rapid-fuzzy |
|
|
249
|
-
|
|
250
|
-
| Small (20 items) |
|
|
251
|
-
| Medium (1K items) | 6,
|
|
252
|
-
| Large (10K items) |
|
|
317
|
+
| Dataset size | rapid-fuzzy | rapid-fuzzy (indexed) | fuse.js | fuzzysort | uFuzzy |
|
|
318
|
+
|---|---:|---:|---:|---:|---:|
|
|
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 |
|
|
253
322
|
|
|
254
323
|
</details>
|
|
255
324
|
|
|
256
325
|
### Closest Match (Levenshtein-based)
|
|
257
326
|
|
|
258
|
-
| Dataset size | rapid-fuzzy |
|
|
327
|
+
| Dataset size | rapid-fuzzy | rapid-fuzzy (indexed) | fastest-levenshtein |
|
|
259
328
|
|---|---:|---:|---:|
|
|
260
|
-
| Medium (1K items) | 8,
|
|
261
|
-
| Large (10K items) |
|
|
262
|
-
|
|
263
|
-
> With `FuzzyIndex`, rapid-fuzzy is up to **6.8x faster** than fastest-levenshtein for closest-match lookups.
|
|
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 |
|
|
264
331
|
|
|
265
|
-
|
|
332
|
+
> In indexed mode (`FuzzyIndex`), rapid-fuzzy is up to **224x faster** than fastest-levenshtein for closest-match lookups.
|
|
266
333
|
|
|
267
|
-
|
|
268
|
-
- **FuzzyIndex**: Pre-computing string data on the Rust side gives an additional **3–5x speedup** over standalone `search()`, making it the recommended approach for repeated searches.
|
|
269
|
-
- **vs fastest-levenshtein**: With `FuzzyIndex`, closest-match is **6.8x faster** at scale. Even standalone `closest()` wins on large datasets.
|
|
270
|
-
- **fuzzysort** uses a different (substring-based) matching algorithm that is extremely fast but produces different ranking results. Choose based on your matching needs.
|
|
334
|
+
### Key takeaways
|
|
271
335
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
pnpm run bench # JavaScript benchmarks
|
|
276
|
-
cargo bench # Rust internal benchmarks
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
## Choosing an Algorithm
|
|
280
|
-
|
|
281
|
-
| Use case | Recommended | Why |
|
|
282
|
-
|---|---|---|
|
|
283
|
-
| Typo detection / spell check | `levenshtein`, `damerauLevenshtein` | Counts edits; Damerau adds transposition support |
|
|
284
|
-
| Name / address matching | `jaroWinkler`, `tokenSortRatio` | Prefix-weighted or order-independent matching |
|
|
285
|
-
| Document / text similarity | `sorensenDice` | Bigram-based; handles longer text well |
|
|
286
|
-
| Normalized comparison (0–1) | `normalizedLevenshtein` | Length-independent similarity score |
|
|
287
|
-
| Reordered words / messy data | `tokenSortRatio`, `tokenSetRatio` | Handles word order differences and extra tokens |
|
|
288
|
-
| Substring / abbreviation matching | `partialRatio` | Finds best partial match within longer strings |
|
|
289
|
-
| Best-effort similarity | `weightedRatio` | Picks the best score across all methods automatically |
|
|
290
|
-
| Interactive fuzzy search | `search`, `closest` | Nucleo algorithm (same as Helix editor) |
|
|
291
|
-
| Repeated search on same data | `FuzzyIndex`, `FuzzyObjectIndex` | Persistent Rust-side index, 3–5x faster than standalone |
|
|
292
|
-
|
|
293
|
-
**Return types:**
|
|
294
|
-
|
|
295
|
-
- `levenshtein`, `damerauLevenshtein` → integer (edit count)
|
|
296
|
-
- `jaro`, `jaroWinkler`, `sorensenDice`, `normalizedLevenshtein` → float between 0.0 (no match) and 1.0 (identical)
|
|
297
|
-
- `tokenSortRatio`, `tokenSetRatio`, `partialRatio`, `weightedRatio` → float between 0.0 and 1.0
|
|
298
|
-
- `search` → array of `{ item, score, index, positions }` sorted by relevance (score: 0.0–1.0)
|
|
336
|
+
- **vs fuse.js**: `FuzzyIndex` is **218x–7,572x faster** depending on dataset size. Even standalone `search()` is 19–46x 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).
|
|
299
339
|
|
|
300
340
|
## Why rapid-fuzzy?
|
|
301
341
|
|
|
302
|
-
| | rapid-fuzzy | fuse.js | fastest-levenshtein | fuzzysort |
|
|
303
|
-
|
|
304
|
-
| **Algorithms** | 9 (Levenshtein, Jaro, Dice, …) | Bitap | Levenshtein | Substring |
|
|
305
|
-
| **Runtime** | Rust native + WASM | Pure JS | Pure JS | Pure JS |
|
|
306
|
-
| **Object search** | ✅ weighted keys | ✅ | — | ✅ |
|
|
307
|
-
| **Persistent index** | ✅ FuzzyIndex / FuzzyObjectIndex | — | — | ✅ prepared targets |
|
|
308
|
-
| **
|
|
309
|
-
| **
|
|
310
|
-
| **
|
|
311
|
-
| **
|
|
312
|
-
| **
|
|
313
|
-
| **
|
|
314
|
-
| **
|
|
342
|
+
| | rapid-fuzzy | fuse.js | fastest-levenshtein | fuzzysort | uFuzzy |
|
|
343
|
+
|---|:---:|:---:|:---:|:---:|:---:|
|
|
344
|
+
| **Algorithms** | 9 (Levenshtein, Jaro, Dice, …) | Bitap | Levenshtein | Substring | Regex-based |
|
|
345
|
+
| **Runtime** | Rust native + WASM | Pure JS | Pure JS | Pure JS | Pure JS |
|
|
346
|
+
| **Object search** | ✅ weighted keys | ✅ | — | ✅ | — |
|
|
347
|
+
| **Persistent index** | ✅ FuzzyIndex / FuzzyObjectIndex | — | — | ✅ prepared targets | — |
|
|
348
|
+
| **Query syntax** | ✅ exclude, prefix, suffix, exact | ✅ extended search | — | — | partial (`-` only) |
|
|
349
|
+
| **Out-of-order matching** | ✅ automatic | — | — | — | ✅ with option |
|
|
350
|
+
| **Diacritics** | ✅ automatic | ✅ option | — | ✅ auto | ✅ `latinize()` |
|
|
351
|
+
| **Score threshold** | ✅ | ✅ | — | ✅ | — |
|
|
352
|
+
| **Match positions** | ✅ | ✅ | — | ✅ | ✅ |
|
|
353
|
+
| **Highlight utility** | ✅ | — | — | ✅ | ✅ |
|
|
354
|
+
| **Batch API** | ✅ | — | — | — | — |
|
|
355
|
+
| **Node.js native** | ✅ napi-rs | — | — | — | — |
|
|
356
|
+
| **Browser** | ✅ WASM (~200 KB gzipped) | ✅ | ✅ | ✅ | ✅ |
|
|
357
|
+
| **TypeScript** | ✅ full | ✅ full | ✅ | ✅ | ✅ |
|
|
315
358
|
|
|
316
359
|
## Migration Guides
|
|
317
360
|
|
|
318
361
|
Switching from another library? These guides provide API mapping tables, code examples, and performance comparisons:
|
|
319
362
|
|
|
320
363
|
- [**From string-similarity**](docs/migration/from-string-similarity.md) — Same Dice coefficient algorithm, now maintained and faster
|
|
321
|
-
- [**From fuse.js**](docs/migration/from-fuse-js.md) —
|
|
364
|
+
- [**From fuse.js**](docs/migration/from-fuse-js.md) — Up to 7,000x faster fuzzy search with FuzzyIndex
|
|
322
365
|
- [**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
|
|
367
|
+
- [**From uFuzzy**](docs/migration/from-ufuzzy.md) — Weighted object search, batch APIs, and persistent indexes
|
|
323
368
|
|
|
324
369
|
## License
|
|
325
370
|
|
package/index.d.ts
CHANGED
|
@@ -41,6 +41,21 @@ export declare class FuzzyIndex {
|
|
|
41
41
|
remove(index: number): boolean
|
|
42
42
|
/** Free the internal data. After calling this, the index is empty. */
|
|
43
43
|
destroy(): void
|
|
44
|
+
/**
|
|
45
|
+
* Serialize the index to a compact binary format.
|
|
46
|
+
*
|
|
47
|
+
* The returned Buffer can be written to disk, stored in IndexedDB,
|
|
48
|
+
* or transferred over the network. Use `FuzzyIndex.deserialize()` to
|
|
49
|
+
* reconstruct the index.
|
|
50
|
+
*/
|
|
51
|
+
serialize(): Buffer
|
|
52
|
+
/**
|
|
53
|
+
* Reconstruct a FuzzyIndex from a previously serialized Buffer.
|
|
54
|
+
*
|
|
55
|
+
* Pre-computes Utf32String and character masks from the stored items,
|
|
56
|
+
* so the returned index is immediately ready for searching.
|
|
57
|
+
*/
|
|
58
|
+
static deserialize(data: Buffer): FuzzyIndex
|
|
44
59
|
}
|
|
45
60
|
|
|
46
61
|
/**
|
|
@@ -75,12 +90,14 @@ export declare class KeyedFuzzyIndex {
|
|
|
75
90
|
* Add a single item to the index.
|
|
76
91
|
*
|
|
77
92
|
* `key_values` must have the same length as the number of keys.
|
|
93
|
+
* Throws if the length does not match.
|
|
78
94
|
*/
|
|
79
95
|
add(keyValues: Array<string>): void
|
|
80
96
|
/**
|
|
81
97
|
* Add multiple items to the index at once.
|
|
82
98
|
*
|
|
83
99
|
* Each element of `items_key_values` is an array of key values for one item.
|
|
100
|
+
* Throws if any element has the wrong number of key values.
|
|
84
101
|
*/
|
|
85
102
|
addMany(itemsKeyValues: Array<Array<string>>): void
|
|
86
103
|
/**
|
|
@@ -203,6 +220,22 @@ export declare function levenshteinBatch(pairs: Array<Array<string>>): Array<num
|
|
|
203
220
|
*/
|
|
204
221
|
export declare function levenshteinMany(reference: string, candidates: Array<string>): Array<number>
|
|
205
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Classification of how a query matched an item.
|
|
225
|
+
*
|
|
226
|
+
* Derived from the matched character positions:
|
|
227
|
+
* - **Exact**: all positions consecutive from index 0, covering every character in the item.
|
|
228
|
+
* - **Prefix**: all positions consecutive from index 0, but the item is longer.
|
|
229
|
+
* - **Contains**: all positions consecutive (a substring match), not starting at 0.
|
|
230
|
+
* - **Fuzzy**: positions have gaps (character-level fuzzy match).
|
|
231
|
+
*/
|
|
232
|
+
export declare const enum MatchType {
|
|
233
|
+
Exact = 'Exact',
|
|
234
|
+
Prefix = 'Prefix',
|
|
235
|
+
Contains = 'Contains',
|
|
236
|
+
Fuzzy = 'Fuzzy'
|
|
237
|
+
}
|
|
238
|
+
|
|
206
239
|
/**
|
|
207
240
|
* Compute the normalized Levenshtein similarity between two strings.
|
|
208
241
|
*
|
|
@@ -285,6 +318,12 @@ export interface SearchOptions {
|
|
|
285
318
|
* (case-insensitive unless the query contains uppercase characters).
|
|
286
319
|
*/
|
|
287
320
|
isCaseSensitive?: boolean
|
|
321
|
+
/**
|
|
322
|
+
* If true, return all items when the query is empty (or whitespace-only).
|
|
323
|
+
* Useful for filter-as-you-type UIs where the full list should appear
|
|
324
|
+
* before the user starts typing. Default is false.
|
|
325
|
+
*/
|
|
326
|
+
returnAllOnEmpty?: boolean
|
|
288
327
|
}
|
|
289
328
|
|
|
290
329
|
/** A single fuzzy search result with the matched item and its score. */
|
|
@@ -300,6 +339,12 @@ export interface SearchResult {
|
|
|
300
339
|
* Empty unless `includePositions` is set to true in SearchOptions.
|
|
301
340
|
*/
|
|
302
341
|
positions: Array<number>
|
|
342
|
+
/**
|
|
343
|
+
* How the query matched this item (Exact, Prefix, Contains, or Fuzzy).
|
|
344
|
+
* Only present when `includePositions` is set to true in SearchOptions.
|
|
345
|
+
* Derived from positions at zero additional cost.
|
|
346
|
+
*/
|
|
347
|
+
matchType?: MatchType
|
|
303
348
|
}
|
|
304
349
|
|
|
305
350
|
/**
|
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 !== '0.
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
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 !== '0.
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
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.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
|
@@ -591,6 +591,7 @@ module.exports.jaroWinklerMany = nativeBinding.jaroWinklerMany
|
|
|
591
591
|
module.exports.levenshtein = nativeBinding.levenshtein
|
|
592
592
|
module.exports.levenshteinBatch = nativeBinding.levenshteinBatch
|
|
593
593
|
module.exports.levenshteinMany = nativeBinding.levenshteinMany
|
|
594
|
+
module.exports.MatchType = nativeBinding.MatchType
|
|
594
595
|
module.exports.normalizedLevenshtein = nativeBinding.normalizedLevenshtein
|
|
595
596
|
module.exports.normalizedLevenshteinBatch = nativeBinding.normalizedLevenshteinBatch
|
|
596
597
|
module.exports.normalizedLevenshteinMany = nativeBinding.normalizedLevenshteinMany
|
package/index.mjs
CHANGED
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
|
/**
|
|
@@ -85,7 +85,7 @@ export declare class FuzzyObjectIndex<T> {
|
|
|
85
85
|
search(
|
|
86
86
|
query: string,
|
|
87
87
|
options?: ObjectIndexSearchOptions,
|
|
88
|
-
): Array<
|
|
88
|
+
): Array<ObjectSearchResult<T>>;
|
|
89
89
|
|
|
90
90
|
/** Find the closest matching object, or null if no match. */
|
|
91
91
|
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": "0.
|
|
3
|
+
"version": "1.0.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",
|
|
@@ -107,6 +132,7 @@
|
|
|
107
132
|
"@commitlint/config-conventional": "^20.4.4",
|
|
108
133
|
"@emnapi/core": "^1.9.0",
|
|
109
134
|
"@emnapi/runtime": "^1.9.0",
|
|
135
|
+
"@leeoniya/ufuzzy": "^1.0.19",
|
|
110
136
|
"@napi-rs/cli": "^3.5.1",
|
|
111
137
|
"@napi-rs/wasm-runtime": "^1.1.1",
|
|
112
138
|
"@playwright/test": "^1.58.2",
|
|
@@ -131,14 +157,14 @@
|
|
|
131
157
|
]
|
|
132
158
|
},
|
|
133
159
|
"optionalDependencies": {
|
|
134
|
-
"rapid-fuzzy-darwin-x64": "0.
|
|
135
|
-
"rapid-fuzzy-darwin-arm64": "0.
|
|
136
|
-
"rapid-fuzzy-linux-x64-gnu": "0.
|
|
137
|
-
"rapid-fuzzy-linux-x64-musl": "0.
|
|
138
|
-
"rapid-fuzzy-linux-arm64-gnu": "0.
|
|
139
|
-
"rapid-fuzzy-linux-arm64-musl": "0.
|
|
140
|
-
"rapid-fuzzy-win32-x64-msvc": "0.
|
|
141
|
-
"rapid-fuzzy-win32-arm64-msvc": "0.
|
|
142
|
-
"rapid-fuzzy-wasm32-wasi": "0.
|
|
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"
|
|
143
169
|
}
|
|
144
170
|
}
|