rapid-fuzzy 0.3.0 → 0.5.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 CHANGED
@@ -69,6 +69,9 @@ search('app', items, 5);
69
69
  const [match] = search('hlo', ['hello world'], { includePositions: true });
70
70
  // → { item: 'hello world', score: 0.75, index: 0, positions: [0, 2, 4] }
71
71
 
72
+ // Case-sensitive matching (default: smart case)
73
+ search('Type', items, { isCaseSensitive: true });
74
+
72
75
  // Find the single best match
73
76
  closest('tsc', ['TypeScript', 'JavaScript', 'Python']);
74
77
  // → 'TypeScript'
@@ -78,6 +81,91 @@ closest('xyz', items, 0.5);
78
81
  // → null
79
82
  ```
80
83
 
84
+ ### Object Search
85
+
86
+ Search across object properties with weighted keys — a drop-in replacement for fuse.js's `keys` option:
87
+
88
+ ```typescript
89
+ import { searchObjects } from 'rapid-fuzzy';
90
+
91
+ const users = [
92
+ { name: 'John Smith', email: 'john@example.com' },
93
+ { name: 'Jane Doe', email: 'jane@example.com' },
94
+ { name: 'Bob Johnson', email: 'bob@test.com' },
95
+ ];
96
+
97
+ // Search across multiple keys
98
+ const results = searchObjects('john', users, {
99
+ keys: ['name', 'email'],
100
+ });
101
+ // → [{ item: { name: 'John Smith', ... }, score: 0.95, keyScores: [0.98, 0.85], index: 0 }]
102
+
103
+ // Weighted keys — prioritize name matches over email
104
+ searchObjects('john', users, {
105
+ keys: [
106
+ { name: 'name', weight: 2.0 },
107
+ { name: 'email', weight: 1.0 },
108
+ ],
109
+ });
110
+
111
+ // Nested key paths
112
+ searchObjects('new york', items, { keys: ['address.city'] });
113
+ ```
114
+
115
+ ### Persistent Index
116
+
117
+ For applications that search the same dataset repeatedly (autocomplete, file finders, etc.), use `FuzzyIndex` or `FuzzyObjectIndex` to keep data on the Rust side and eliminate per-search FFI overhead:
118
+
119
+ ```typescript
120
+ import { FuzzyIndex, FuzzyObjectIndex } from 'rapid-fuzzy';
121
+
122
+ // String search index — up to 5x faster than standalone search()
123
+ const index = new FuzzyIndex(['TypeScript', 'JavaScript', 'Python', ...]);
124
+
125
+ index.search('typscript', { maxResults: 5 });
126
+ index.closest('tsc');
127
+
128
+ // Mutate the index without rebuilding
129
+ index.add('Rust');
130
+ index.remove(2); // swap-remove by index
131
+
132
+ // Object search index — keeps objects on the JS side, keys on the Rust side
133
+ const userIndex = new FuzzyObjectIndex(users, {
134
+ keys: [
135
+ { name: 'name', weight: 2.0 },
136
+ { name: 'email', weight: 1.0 },
137
+ ],
138
+ });
139
+
140
+ userIndex.search('john', { maxResults: 10 });
141
+
142
+ // Free Rust-side memory when done
143
+ index.destroy();
144
+ userIndex.destroy();
145
+ ```
146
+
147
+ ### Match Highlighting
148
+
149
+ Convert matched positions into highlighted markup for UI rendering:
150
+
151
+ ```typescript
152
+ import { search, highlight, highlightRanges } from 'rapid-fuzzy';
153
+
154
+ const results = search('fzy', ['fuzzy'], { includePositions: true });
155
+ const { item, positions } = results[0];
156
+
157
+ // String markers
158
+ highlight(item, positions, '<b>', '</b>');
159
+ // → '<b>f</b>u<b>zy</b>'
160
+
161
+ // Callback (React, JSX, custom DOM)
162
+ highlight(item, positions, (matched) => `<mark>${matched}</mark>`);
163
+
164
+ // Raw ranges for custom rendering
165
+ highlightRanges(item, positions);
166
+ // → [{ start: 0, end: 1, matched: true }, { start: 1, end: 2, matched: false }, ...]
167
+ ```
168
+
81
169
  ### Token-Based Matching
82
170
 
83
171
  Order-independent and partial string matching, inspired by Python's [RapidFuzz](https://github.com/rapidfuzz/RapidFuzz):
@@ -133,37 +221,52 @@ Measured on Apple M-series with Node.js v22 using [Vitest bench](https://vitest.
133
221
 
134
222
  ### Distance Functions
135
223
 
224
+ <img src=".github/assets/bench-distance.svg" alt="Distance function performance chart" width="680" />
225
+
226
+ <details>
227
+ <summary>Raw numbers</summary>
228
+
136
229
  | Function | rapid-fuzzy | fastest-levenshtein | leven | string-similarity |
137
230
  |---|---:|---:|---:|---:|
138
- | Levenshtein | 193,593 ops/s | **774,820 ops/s** | 204,047 ops/s | — |
139
- | Normalized Levenshtein | **136,854 ops/s** | — | — | — |
140
- | Sorensen-Dice | **144,698 ops/s** | — | — | 84,108 ops/s |
141
- | Jaro-Winkler | **291,673 ops/s** | — | — | — |
142
- | Damerau-Levenshtein | **72,238 ops/s** | — | — | — |
231
+ | Levenshtein | 528,195 ops/s | **739,107 ops/s** | 221,817 ops/s | — |
232
+ | Normalized Levenshtein | **534,231 ops/s** | — | — | — |
233
+ | Sorensen-Dice | **149,567 ops/s** | — | — | 82,908 ops/s |
234
+ | Jaro-Winkler | **278,554 ops/s** | — | — | — |
235
+ | Damerau-Levenshtein | **112,370 ops/s** | — | — | — |
236
+
237
+ </details>
143
238
 
144
- > **Note**: For single-pair Levenshtein distance, fastest-levenshtein is faster due to its highly optimized pure-JS implementation that avoids FFI overhead. rapid-fuzzy provides broader algorithm coverage and excels in batch / search scenarios.
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.4x faster** than leven, and provides broader algorithm coverage plus batch / search scenarios.
145
240
 
146
241
  ### Search Performance
147
242
 
148
- | Dataset size | rapid-fuzzy | fuse.js | fuzzysort |
149
- |---|---:|---:|---:|
150
- | Small (20 items) | 179,222 ops/s | 109,059 ops/s | **2,501,773 ops/s** |
151
- | Medium (1K items) | 6,614 ops/s | 381 ops/s | **63,032 ops/s** |
152
- | Large (10K items) | 794 ops/s | 20 ops/s | **28,616 ops/s** |
243
+ <img src=".github/assets/bench-search.svg" alt="Search performance chart — rapid-fuzzy vs fuse.js vs fuzzysort" width="680" />
244
+
245
+ <details>
246
+ <summary>Raw numbers</summary>
247
+
248
+ | Dataset size | rapid-fuzzy | FuzzyIndex | fuse.js | fuzzysort |
249
+ |---|---:|---:|---:|---:|
250
+ | Small (20 items) | 174,812 ops/s | 406,269 ops/s | 127,167 ops/s | **2,502,299 ops/s** |
251
+ | Medium (1K items) | 6,531 ops/s | 22,014 ops/s | 395 ops/s | **62,845 ops/s** |
252
+ | Large (10K items) | 794 ops/s | 3,985 ops/s | 20 ops/s | **28,846 ops/s** |
253
+
254
+ </details>
153
255
 
154
256
  ### Closest Match (Levenshtein-based)
155
257
 
156
- | Dataset size | rapid-fuzzy | fastest-levenshtein |
157
- |---|---:|---:|
158
- | Medium (1K items) | 8,416 ops/s | **8,762 ops/s** |
159
- | Large (10K items) | **905 ops/s** | 662 ops/s |
258
+ | Dataset size | rapid-fuzzy | FuzzyIndex | fastest-levenshtein |
259
+ |---|---:|---:|---:|
260
+ | Medium (1K items) | 8,304 ops/s | **60,469 ops/s** | 8,946 ops/s |
261
+ | Large (10K items) | 757 ops/s | **4,103 ops/s** | 604 ops/s |
160
262
 
161
- > rapid-fuzzy is up to **1.4x faster** than fastest-levenshtein for closest-match lookups on large datasets.
263
+ > With `FuzzyIndex`, rapid-fuzzy is up to **6.8x faster** than fastest-levenshtein for closest-match lookups.
162
264
 
163
265
  ### Why these numbers matter
164
266
 
165
267
  - **vs fuse.js**: rapid-fuzzy is **17x faster** on medium datasets and **40x faster** on large datasets for fuzzy search.
166
- - **vs fastest-levenshtein**: rapid-fuzzy wins on closest-match at scale where batch FFI overhead is amortized.
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.
167
270
  - **fuzzysort** uses a different (substring-based) matching algorithm that is extremely fast but produces different ranking results. Choose based on your matching needs.
168
271
 
169
272
  Run benchmarks yourself:
@@ -185,6 +288,7 @@ cargo bench # Rust internal benchmarks
185
288
  | Substring / abbreviation matching | `partialRatio` | Finds best partial match within longer strings |
186
289
  | Best-effort similarity | `weightedRatio` | Picks the best score across all methods automatically |
187
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 |
188
292
 
189
293
  **Return types:**
190
294
 
@@ -196,22 +300,25 @@ cargo bench # Rust internal benchmarks
196
300
  ## Why rapid-fuzzy?
197
301
 
198
302
  | | rapid-fuzzy | fuse.js | fastest-levenshtein | fuzzysort |
199
- |---|---|---|---|---|
200
- | **Algorithms** | Levenshtein, Jaro-Winkler, Sorensen-Dice, Damerau-Levenshtein, token sort/set, partial ratio, fuzzy search | Bitap-based fuzzy | Levenshtein only | Substring fuzzy |
201
- | **Runtime** | Rust (native + WASM) | Pure JS | Pure JS | Pure JS |
202
- | **Score threshold** | Yes (minScore) | Yes (threshold) | No | Yes (threshold) |
203
- | **Match positions** | Yes (includePositions) | Yes | No | Yes |
204
- | **Batch API** | Yes | No | No | No |
205
- | **Node.js native** | Yes (napi-rs) | No | No | No |
206
- | **Browser support** | Yes (WASM) | Yes | Yes | Yes |
207
- | **TypeScript** | Full (auto-generated) | Full | Yes | Yes |
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
+ | **Score threshold** | | | | |
309
+ | **Match positions** | | | | |
310
+ | **Highlight utility** | | | | |
311
+ | **Batch API** | | | | |
312
+ | **Node.js native** | ✅ napi-rs | — | — | — |
313
+ | **Browser** | ✅ WASM | ✅ | ✅ | ✅ |
314
+ | **TypeScript** | ✅ full | ✅ full | ✅ | ✅ |
208
315
 
209
316
  ## Migration Guides
210
317
 
211
318
  Switching from another library? These guides provide API mapping tables, code examples, and performance comparisons:
212
319
 
213
320
  - [**From string-similarity**](docs/migration/from-string-similarity.md) — Same Dice coefficient algorithm, now maintained and faster
214
- - [**From fuse.js**](docs/migration/from-fuse-js.md) — 1341x faster fuzzy search with a simpler API
321
+ - [**From fuse.js**](docs/migration/from-fuse-js.md) — 1740x faster fuzzy search with a simpler API
215
322
  - [**From leven / fastest-levenshtein**](docs/migration/from-leven.md) — Multi-algorithm upgrade with batch APIs
216
323
 
217
324
  ## License
package/browser.js CHANGED
@@ -1 +1,4 @@
1
1
  export * from 'rapid-fuzzy-wasm32-wasi'
2
+
3
+ // --- JS utilities (appended by scripts/patch-binding.js) ---
4
+ export { highlight, highlightRanges } from './highlight.mjs';
package/highlight.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ /** A range within a string, indicating whether it was matched. */
2
+ export interface HighlightRange {
3
+ /** Start index (inclusive). */
4
+ start: number;
5
+ /** End index (exclusive). */
6
+ end: number;
7
+ /** Whether this range was part of the match. */
8
+ matched: boolean;
9
+ }
10
+
11
+ /**
12
+ * Highlight matched characters in a search result string.
13
+ *
14
+ * Use with `SearchResult.positions` from a search with `includePositions: true`.
15
+ *
16
+ * @example String markers
17
+ * ```typescript
18
+ * const results = search('fzy', ['fuzzy'], { includePositions: true });
19
+ * highlight(results[0].item, results[0].positions, '<b>', '</b>');
20
+ * // → '<b>f</b>u<b>zy</b>'
21
+ * ```
22
+ *
23
+ * @example Callback (React, custom DOM, etc.)
24
+ * ```typescript
25
+ * highlight(result.item, result.positions, (matched) => `<mark>${matched}</mark>`);
26
+ * ```
27
+ */
28
+ export declare function highlight(
29
+ item: string,
30
+ positions: Array<number>,
31
+ open: string,
32
+ close: string,
33
+ ): string;
34
+ export declare function highlight(
35
+ item: string,
36
+ positions: Array<number>,
37
+ callback: (matched: string) => string,
38
+ ): string;
39
+
40
+ /**
41
+ * Convert matched positions into an array of ranges for custom rendering.
42
+ *
43
+ * Each range indicates a contiguous segment of the string and whether it was
44
+ * part of the match. Useful for building custom highlight components.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const ranges = highlightRanges(result.item, result.positions);
49
+ * // → [{ start: 0, end: 1, matched: true }, { start: 1, end: 2, matched: false }, ...]
50
+ * ```
51
+ */
52
+ export declare function highlightRanges(
53
+ item: string,
54
+ positions: Array<number>,
55
+ ): Array<HighlightRange>;
package/highlight.js ADDED
@@ -0,0 +1,58 @@
1
+ // Pure JS highlight utilities — works in both Node.js and browser environments.
2
+ // This file is manually maintained (not auto-generated by napi-rs).
3
+
4
+ 'use strict';
5
+
6
+ /**
7
+ * @param {string} item
8
+ * @param {number[]} positions
9
+ * @returns {Array<{start: number, end: number, matched: boolean}>}
10
+ */
11
+ function highlightRanges(item, positions) {
12
+ if (!item) return [];
13
+ if (!positions || positions.length === 0) {
14
+ return [{ start: 0, end: item.length, matched: false }];
15
+ }
16
+
17
+ const set = new Set(positions);
18
+ const ranges = [];
19
+ let i = 0;
20
+
21
+ while (i < item.length) {
22
+ const matched = set.has(i);
23
+ const start = i;
24
+ while (i < item.length && set.has(i) === matched) i++;
25
+ ranges.push({ start, end: i, matched });
26
+ }
27
+
28
+ return ranges;
29
+ }
30
+
31
+ /**
32
+ * @param {string} item
33
+ * @param {number[]} positions
34
+ * @param {string | ((substring: string) => string)} openOrCallback
35
+ * @param {string} [close]
36
+ * @returns {string}
37
+ */
38
+ function highlight(item, positions, openOrCallback, close) {
39
+ if (!positions || positions.length === 0) return item;
40
+
41
+ const ranges = highlightRanges(item, positions);
42
+ const useCallback = typeof openOrCallback === 'function';
43
+
44
+ const parts = [];
45
+ for (const range of ranges) {
46
+ const segment = item.slice(range.start, range.end);
47
+ if (range.matched) {
48
+ parts.push(useCallback ? openOrCallback(segment) : openOrCallback + segment + (close ?? ''));
49
+ } else {
50
+ parts.push(segment);
51
+ }
52
+ }
53
+
54
+ return parts.join('');
55
+ }
56
+
57
+ module.exports.highlight = highlight;
58
+ module.exports.highlightRanges = highlightRanges;
package/highlight.mjs ADDED
@@ -0,0 +1,4 @@
1
+ // ESM re-export — single source of truth is highlight.js (CJS).
2
+ // Node.js detects named exports from CJS via static analysis.
3
+ // Bundlers (webpack, vite, rollup) handle CJS interop natively.
4
+ export { highlight, highlightRanges } from './highlight.js';
package/index.d.mts CHANGED
@@ -1 +1,11 @@
1
1
  export * from './index.d.ts';
2
+ export { highlight, highlightRanges } from './highlight.d.ts';
3
+ export type { HighlightRange } from './highlight.d.ts';
4
+ export { searchObjects, FuzzyObjectIndex } from './objects';
5
+ export type {
6
+ KeyConfig,
7
+ ObjectSearchOptions,
8
+ ObjectSearchResult,
9
+ ObjectIndexOptions,
10
+ ObjectIndexSearchOptions,
11
+ } from './objects';
package/index.d.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  *
6
6
  * Holds items in memory on the Rust side, avoiding repeated FFI overhead
7
7
  * for applications that search the same dataset multiple times.
8
+ * Pre-computes Utf32String representations for each item, eliminating
9
+ * per-search string conversion overhead.
8
10
  * Memory is freed when the JavaScript garbage collector collects the instance
9
11
  * or when `destroy()` is called explicitly.
10
12
  */
@@ -41,6 +43,56 @@ export declare class FuzzyIndex {
41
43
  destroy(): void
42
44
  }
43
45
 
46
+ /**
47
+ * A persistent multi-key fuzzy search index backed by Rust-side data.
48
+ *
49
+ * Holds key text arrays and weights in memory on the Rust side,
50
+ * avoiding repeated FFI overhead for applications that search the
51
+ * same dataset multiple times with multiple keys.
52
+ * Pre-computes Utf32String representations and reuses the Matcher
53
+ * instance for optimal repeated-search performance.
54
+ *
55
+ * Typically wrapped by a JS-side `FuzzyObjectIndex` class that maps
56
+ * results back to original objects.
57
+ */
58
+ export declare class KeyedFuzzyIndex {
59
+ /**
60
+ * Create a new KeyedFuzzyIndex.
61
+ *
62
+ * `key_texts[k]` is an array of strings for key `k`, one per item.
63
+ * All inner arrays must have the same length (the number of items).
64
+ */
65
+ constructor(keyTexts: Array<Array<string>>, weights: Array<number>)
66
+ /** Return the number of items in the index. */
67
+ get size(): number
68
+ /**
69
+ * Search the index for items matching the query.
70
+ *
71
+ * Returns results sorted by combined weighted score (best match first).
72
+ */
73
+ search(query: string, options?: SearchOptions | undefined | null): Array<KeySearchResult>
74
+ /**
75
+ * Add a single item to the index.
76
+ *
77
+ * `key_values` must have the same length as the number of keys.
78
+ */
79
+ add(keyValues: Array<string>): void
80
+ /**
81
+ * Add multiple items to the index at once.
82
+ *
83
+ * Each element of `items_key_values` is an array of key values for one item.
84
+ */
85
+ addMany(itemsKeyValues: Array<Array<string>>): void
86
+ /**
87
+ * Remove the item at the given index.
88
+ *
89
+ * Uses swap-remove for O(1) performance. Returns false if out of bounds.
90
+ */
91
+ remove(index: number): boolean
92
+ /** Free the internal data. After calling this, the index is empty. */
93
+ destroy(): void
94
+ }
95
+
44
96
  /**
45
97
  * Find the closest matching string from a list.
46
98
  *
@@ -114,6 +166,19 @@ export declare function jaroWinklerBatch(pairs: Array<Array<string>>): Array<num
114
166
  */
115
167
  export declare function jaroWinklerMany(reference: string, candidates: Array<string>): Array<number>
116
168
 
169
+ /** A single result from multi-key fuzzy search. */
170
+ export interface KeySearchResult {
171
+ /** The index of the item in the original input array. */
172
+ index: number
173
+ /** The combined weighted score normalized to 0.0-1.0 range. */
174
+ score: number
175
+ /**
176
+ * Per-key scores in the same order as the input keys.
177
+ * A score of 0.0 means the item did not match on that key.
178
+ */
179
+ keyScores: Array<number>
180
+ }
181
+
117
182
  /**
118
183
  * Compute the Levenshtein distance between two strings.
119
184
  *
@@ -196,6 +261,17 @@ export declare function partialRatioMany(reference: string, candidates: Array<st
196
261
  */
197
262
  export declare function search(query: string, items: Array<string>, options?: number | SearchOptions | undefined | null): Array<SearchResult>
198
263
 
264
+ /**
265
+ * Perform fuzzy search across multiple text keys with weights.
266
+ *
267
+ * `key_texts[k]` is an array of strings for key `k`, one per item.
268
+ * All inner arrays must have the same length (the number of items).
269
+ * `weights` specifies the relative importance of each key.
270
+ *
271
+ * Returns results sorted by combined weighted score (best match first).
272
+ */
273
+ export declare function searchKeys(query: string, keyTexts: Array<Array<string>>, weights: Array<number>, options?: SearchOptions | undefined | null): Array<KeySearchResult>
274
+
199
275
  /** Options for the search function. */
200
276
  export interface SearchOptions {
201
277
  /** Maximum number of results to return. */
@@ -204,6 +280,11 @@ export interface SearchOptions {
204
280
  minScore?: number
205
281
  /** If true, include matched character positions in results. */
206
282
  includePositions?: boolean
283
+ /**
284
+ * If true, matching is case-sensitive. Default is smart case
285
+ * (case-insensitive unless the query contains uppercase characters).
286
+ */
287
+ isCaseSensitive?: boolean
207
288
  }
208
289
 
209
290
  /** A single fuzzy search result with the matched item and its score. */
@@ -314,3 +395,6 @@ export declare function weightedRatioBatch(pairs: Array<Array<string>>): Array<n
314
395
  * Returns an array of similarity scores, one per candidate, in the same order as the input.
315
396
  */
316
397
  export declare function weightedRatioMany(reference: string, candidates: Array<string>): Array<number>
398
+
399
+ // --- JS utilities (appended by scripts/patch-binding.js) ---
400
+ export { highlight, highlightRanges, HighlightRange } from './highlight';
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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
80
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
96
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
117
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
133
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
166
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
185
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
201
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
217
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
253
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
274
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
290
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
308
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
324
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
342
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
358
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
376
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
392
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
410
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
426
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
459
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '0.4.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 0.4.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.3.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 0.3.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
511
+ if (bindingPackageVersion !== '0.4.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 0.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
513
  }
514
514
  return binding
515
515
  } catch (e) {
@@ -577,6 +577,7 @@ if (!nativeBinding) {
577
577
 
578
578
  module.exports = nativeBinding
579
579
  module.exports.FuzzyIndex = nativeBinding.FuzzyIndex
580
+ module.exports.KeyedFuzzyIndex = nativeBinding.KeyedFuzzyIndex
580
581
  module.exports.closest = nativeBinding.closest
581
582
  module.exports.damerauLevenshtein = nativeBinding.damerauLevenshtein
582
583
  module.exports.damerauLevenshteinBatch = nativeBinding.damerauLevenshteinBatch
@@ -597,6 +598,7 @@ module.exports.partialRatio = nativeBinding.partialRatio
597
598
  module.exports.partialRatioBatch = nativeBinding.partialRatioBatch
598
599
  module.exports.partialRatioMany = nativeBinding.partialRatioMany
599
600
  module.exports.search = nativeBinding.search
601
+ module.exports.searchKeys = nativeBinding.searchKeys
600
602
  module.exports.sorensenDice = nativeBinding.sorensenDice
601
603
  module.exports.sorensenDiceBatch = nativeBinding.sorensenDiceBatch
602
604
  module.exports.sorensenDiceMany = nativeBinding.sorensenDiceMany
@@ -609,3 +611,8 @@ module.exports.tokenSortRatioMany = nativeBinding.tokenSortRatioMany
609
611
  module.exports.weightedRatio = nativeBinding.weightedRatio
610
612
  module.exports.weightedRatioBatch = nativeBinding.weightedRatioBatch
611
613
  module.exports.weightedRatioMany = nativeBinding.weightedRatioMany
614
+
615
+ // --- JS utilities (appended by scripts/patch-binding.js) ---
616
+ const _hl = require('./highlight.js');
617
+ module.exports.highlight = _hl.highlight;
618
+ module.exports.highlightRanges = _hl.highlightRanges;
package/index.mjs CHANGED
@@ -6,6 +6,7 @@ const binding = require('./index.js');
6
6
  export const {
7
7
  FuzzyIndex,
8
8
  closest,
9
+ searchKeys,
9
10
  damerauLevenshtein,
10
11
  damerauLevenshteinBatch,
11
12
  damerauLevenshteinMany,
@@ -37,4 +38,8 @@ export const {
37
38
  weightedRatio,
38
39
  weightedRatioBatch,
39
40
  weightedRatioMany,
40
- } = binding;
41
+ highlight,
42
+ highlightRanges,
43
+ } = { ...binding, ...require('./highlight.js') };
44
+
45
+ export const { searchObjects, FuzzyObjectIndex } = require('./objects.js');
package/objects.d.ts ADDED
@@ -0,0 +1,104 @@
1
+ import type { SearchOptions } from './index';
2
+
3
+ export interface KeyConfig {
4
+ name: string;
5
+ weight?: number;
6
+ }
7
+
8
+ export interface ObjectSearchOptions extends SearchOptions {
9
+ keys: Array<string | KeyConfig>;
10
+ }
11
+
12
+ export interface ObjectSearchResult<T> {
13
+ item: T;
14
+ index: number;
15
+ score: number;
16
+ 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
+ }
23
+
24
+ /**
25
+ * Perform fuzzy search across object arrays with weighted keys.
26
+ *
27
+ * Wraps `searchKeys()` with an ergonomic API that accepts row-oriented
28
+ * objects and returns matched items directly.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const users = [
33
+ * { name: 'John Smith', email: 'john@example.com' },
34
+ * { name: 'Jane Doe', email: 'jane@example.com' },
35
+ * ];
36
+ *
37
+ * const results = searchObjects('john', users, {
38
+ * keys: [{ name: 'name', weight: 2.0 }, 'email'],
39
+ * });
40
+ * // results[0].item → { name: 'John Smith', email: 'john@example.com' }
41
+ * ```
42
+ */
43
+ export declare function searchObjects<T>(
44
+ query: string,
45
+ items: Array<T>,
46
+ options: ObjectSearchOptions,
47
+ ): Array<ObjectSearchResult<T>>;
48
+
49
+ export interface ObjectIndexOptions {
50
+ keys: Array<string | KeyConfig>;
51
+ }
52
+
53
+ export interface ObjectIndexSearchOptions {
54
+ maxResults?: number;
55
+ minScore?: number;
56
+ isCaseSensitive?: boolean;
57
+ }
58
+
59
+ /**
60
+ * A persistent fuzzy search index for object collections with weighted keys.
61
+ *
62
+ * Pre-computes key texts and stores them on the Rust side for fast repeated
63
+ * searches. Use this when searching the same collection multiple times.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const index = new FuzzyObjectIndex(users, {
68
+ * keys: [{ name: 'name', weight: 2.0 }, 'email'],
69
+ * });
70
+ *
71
+ * const results = index.search('john');
72
+ * // results[0].item → { name: 'John Smith', ... }
73
+ *
74
+ * index.add({ name: 'New User', email: 'new@example.com' });
75
+ * index.destroy(); // free Rust-side memory
76
+ * ```
77
+ */
78
+ export declare class FuzzyObjectIndex<T> {
79
+ constructor(items: Array<T>, options: ObjectIndexOptions);
80
+
81
+ /** Number of items in the index. */
82
+ get size(): number;
83
+
84
+ /** Search for objects matching the query. */
85
+ search(
86
+ query: string,
87
+ options?: ObjectIndexSearchOptions,
88
+ ): Array<Omit<ObjectSearchResult<T>, 'positions'>>;
89
+
90
+ /** Find the closest matching object, or null if no match. */
91
+ closest(query: string, minScore?: number): T | null;
92
+
93
+ /** Add a single item to the index. */
94
+ add(item: T): void;
95
+
96
+ /** Add multiple items at once. */
97
+ addMany(items: Array<T>): void;
98
+
99
+ /** Remove the item at the given index (swap-remove semantics). */
100
+ remove(index: number): boolean;
101
+
102
+ /** Free all internal data. */
103
+ destroy(): void;
104
+ }
package/objects.js ADDED
@@ -0,0 +1,170 @@
1
+ 'use strict';
2
+
3
+ const { searchKeys, KeyedFuzzyIndex } = require('./index.js');
4
+
5
+ /**
6
+ * Get a nested property value from an object using a dot-separated path.
7
+ * @param {Record<string, unknown>} obj
8
+ * @param {string} path
9
+ * @returns {string}
10
+ */
11
+ function getNestedValue(obj, path) {
12
+ let current = obj;
13
+ for (const key of path.split('.')) {
14
+ if (current == null) return '';
15
+ current = current[key];
16
+ }
17
+ return current == null ? '' : String(current);
18
+ }
19
+
20
+ /**
21
+ * Perform fuzzy search across object arrays with weighted keys.
22
+ *
23
+ * Wraps `searchKeys()` with an ergonomic API that accepts row-oriented
24
+ * objects and returns matched items directly.
25
+ *
26
+ * @template T
27
+ * @param {string} query - The search query.
28
+ * @param {T[]} items - Array of objects to search.
29
+ * @param {object} options - Search options with keys configuration.
30
+ * @param {Array<string | { name: string; weight?: number }>} options.keys - Keys to search.
31
+ * @param {number} [options.maxResults] - Maximum results to return.
32
+ * @param {number} [options.minScore] - Minimum score threshold.
33
+ * @param {boolean} [options.isCaseSensitive] - Enable case-sensitive matching.
34
+ * @returns {Array<{ item: T; index: number; score: number; keyScores: number[]; positions: number[] }>}
35
+ */
36
+ function searchObjects(query, items, options) {
37
+ const { keys, ...searchOpts } = options;
38
+
39
+ const normalizedKeys = keys.map((k) =>
40
+ typeof k === 'string' ? { name: k, weight: 1.0 } : { name: k.name, weight: k.weight ?? 1.0 },
41
+ );
42
+
43
+ const keyTexts = normalizedKeys.map((k) => items.map((item) => getNestedValue(item, k.name)));
44
+ const weights = normalizedKeys.map((k) => k.weight);
45
+
46
+ const nativeOpts = Object.keys(searchOpts).length > 0 ? searchOpts : undefined;
47
+
48
+ const results = searchKeys(query, keyTexts, weights, nativeOpts);
49
+
50
+ return results.map((r) => ({
51
+ item: items[r.index],
52
+ index: r.index,
53
+ score: r.score,
54
+ keyScores: r.keyScores,
55
+ positions: r.positions ?? [],
56
+ }));
57
+ }
58
+
59
+ /**
60
+ * A persistent fuzzy search index for object collections with weighted keys.
61
+ *
62
+ * Pre-computes key texts and stores them on the Rust side for fast repeated
63
+ * searches. Use this when searching the same collection multiple times.
64
+ *
65
+ * @template T
66
+ */
67
+ class FuzzyObjectIndex {
68
+ /** @type {T[]} */
69
+ #items;
70
+ /** @type {KeyedFuzzyIndex} */
71
+ #index;
72
+ /** @type {Array<{ name: string; weight: number }>} */
73
+ #keys;
74
+
75
+ /**
76
+ * @param {T[]} items - Array of objects to index.
77
+ * @param {object} options - Index configuration.
78
+ * @param {Array<string | { name: string; weight?: number }>} options.keys - Keys to search.
79
+ */
80
+ constructor(items, options) {
81
+ this.#keys = options.keys.map((k) =>
82
+ typeof k === 'string' ? { name: k, weight: 1.0 } : { name: k.name, weight: k.weight ?? 1.0 },
83
+ );
84
+ this.#items = [...items];
85
+
86
+ const keyTexts = this.#keys.map((k) => items.map((item) => getNestedValue(item, k.name)));
87
+ const weights = this.#keys.map((k) => k.weight);
88
+ this.#index = new KeyedFuzzyIndex(keyTexts, weights);
89
+ }
90
+
91
+ /** Return the number of items in the index. */
92
+ get size() {
93
+ return this.#index.size;
94
+ }
95
+
96
+ /**
97
+ * Search the index for objects matching the query.
98
+ * @param {string} query
99
+ * @param {object} [options]
100
+ * @param {number} [options.maxResults]
101
+ * @param {number} [options.minScore]
102
+ * @param {boolean} [options.isCaseSensitive]
103
+ * @returns {Array<{ item: T; index: number; score: number; keyScores: number[] }>}
104
+ */
105
+ search(query, options) {
106
+ const results = this.#index.search(query, options);
107
+ return results.map((r) => ({
108
+ item: this.#items[r.index],
109
+ index: r.index,
110
+ score: r.score,
111
+ keyScores: r.keyScores,
112
+ }));
113
+ }
114
+
115
+ /**
116
+ * Find the closest matching object.
117
+ * @param {string} query
118
+ * @param {number} [minScore]
119
+ * @returns {T | null}
120
+ */
121
+ closest(query, minScore) {
122
+ const results = this.#index.search(query, { maxResults: 1, minScore });
123
+ return results.length > 0 ? this.#items[results[0].index] : null;
124
+ }
125
+
126
+ /**
127
+ * Add a single item to the index.
128
+ * @param {T} item
129
+ */
130
+ add(item) {
131
+ this.#items.push(item);
132
+ this.#index.add(this.#keys.map((k) => getNestedValue(item, k.name)));
133
+ }
134
+
135
+ /**
136
+ * Add multiple items to the index at once.
137
+ * @param {T[]} items
138
+ */
139
+ addMany(items) {
140
+ for (const item of items) {
141
+ this.#items.push(item);
142
+ }
143
+ this.#index.addMany(items.map((item) => this.#keys.map((k) => getNestedValue(item, k.name))));
144
+ }
145
+
146
+ /**
147
+ * Remove the item at the given index.
148
+ * Uses swap-remove semantics for O(1) performance.
149
+ * @param {number} index
150
+ * @returns {boolean}
151
+ */
152
+ remove(index) {
153
+ if (index < 0 || index >= this.#items.length) return false;
154
+ // Swap-remove to match Rust-side behavior
155
+ const lastIdx = this.#items.length - 1;
156
+ if (index !== lastIdx) {
157
+ this.#items[index] = this.#items[lastIdx];
158
+ }
159
+ this.#items.pop();
160
+ return this.#index.remove(index);
161
+ }
162
+
163
+ /** Free all internal data. */
164
+ destroy() {
165
+ this.#items = [];
166
+ this.#index.destroy();
167
+ }
168
+ }
169
+
170
+ module.exports = { searchObjects, FuzzyObjectIndex };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapid-fuzzy",
3
- "version": "0.3.0",
3
+ "version": "0.5.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",
@@ -46,7 +46,12 @@
46
46
  "index.mjs",
47
47
  "index.d.ts",
48
48
  "index.d.mts",
49
- "browser.js"
49
+ "objects.js",
50
+ "objects.d.ts",
51
+ "browser.js",
52
+ "highlight.js",
53
+ "highlight.mjs",
54
+ "highlight.d.ts"
50
55
  ],
51
56
  "napi": {
52
57
  "binaryName": "rapid-fuzzy",
@@ -68,6 +73,7 @@
68
73
  "packageManager": "pnpm@10.32.1",
69
74
  "scripts": {
70
75
  "build": "napi build --manifest-path crates/core/Cargo.toml --platform --release --js index.js --dts index.d.ts --output-dir .",
76
+ "postbuild": "node scripts/patch-binding.js",
71
77
  "build:debug": "napi build --manifest-path crates/core/Cargo.toml --platform --js index.js --dts index.d.ts --output-dir .",
72
78
  "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",
73
79
  "artifacts": "napi artifacts",
@@ -80,9 +86,13 @@
80
86
  "typecheck": "tsc --noEmit",
81
87
  "test": "vitest run",
82
88
  "test:wasm": "vitest run __test__/wasm.spec.ts",
89
+ "test:browser": "playwright test",
90
+ "test:bun": "bun test e2e/wasm-bun.test.ts",
91
+ "test:deno": "deno test --allow-read --allow-env --allow-net --node-modules-dir=auto e2e/wasm-deno.test.ts",
83
92
  "test:watch": "vitest watch",
84
93
  "bench": "vitest bench",
85
94
  "bench:readme": "npx tsx scripts/update-bench-readme.ts",
95
+ "bench:charts": "npx tsx scripts/generate-bench-charts.ts",
86
96
  "publint": "publint",
87
97
  "bench:rust": "cargo bench -p rapid-fuzzy-bench",
88
98
  "verify": "pnpm run check && cargo clippy -- -W clippy::all && cargo test && pnpm run build && pnpm run typecheck && pnpm test",
@@ -99,6 +109,7 @@
99
109
  "@emnapi/runtime": "^1.9.0",
100
110
  "@napi-rs/cli": "^3.5.1",
101
111
  "@napi-rs/wasm-runtime": "^1.1.1",
112
+ "@playwright/test": "^1.58.2",
102
113
  "@tybys/wasm-util": "^0.10.1",
103
114
  "@types/node": "^24.0.0",
104
115
  "@types/string-similarity": "^4.0.2",
@@ -111,6 +122,7 @@
111
122
  "publint": "^0.3.18",
112
123
  "string-similarity": "^4.0.4",
113
124
  "typescript": "^5.9.3",
125
+ "vite": "^8.0.0",
114
126
  "vitest": "^4.1.0"
115
127
  },
116
128
  "pnpm": {
@@ -119,14 +131,14 @@
119
131
  ]
120
132
  },
121
133
  "optionalDependencies": {
122
- "rapid-fuzzy-darwin-x64": "0.3.0",
123
- "rapid-fuzzy-darwin-arm64": "0.3.0",
124
- "rapid-fuzzy-linux-x64-gnu": "0.3.0",
125
- "rapid-fuzzy-linux-x64-musl": "0.3.0",
126
- "rapid-fuzzy-linux-arm64-gnu": "0.3.0",
127
- "rapid-fuzzy-linux-arm64-musl": "0.3.0",
128
- "rapid-fuzzy-win32-x64-msvc": "0.3.0",
129
- "rapid-fuzzy-win32-arm64-msvc": "0.3.0",
130
- "rapid-fuzzy-wasm32-wasi": "0.3.0"
134
+ "rapid-fuzzy-darwin-x64": "0.5.0",
135
+ "rapid-fuzzy-darwin-arm64": "0.5.0",
136
+ "rapid-fuzzy-linux-x64-gnu": "0.5.0",
137
+ "rapid-fuzzy-linux-x64-musl": "0.5.0",
138
+ "rapid-fuzzy-linux-arm64-gnu": "0.5.0",
139
+ "rapid-fuzzy-linux-arm64-musl": "0.5.0",
140
+ "rapid-fuzzy-win32-x64-msvc": "0.5.0",
141
+ "rapid-fuzzy-win32-arm64-msvc": "0.5.0",
142
+ "rapid-fuzzy-wasm32-wasi": "0.5.0"
131
143
  }
132
144
  }