Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup and opts #81

Merged
merged 6 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {ratio} from './dist/esm/fuzzball.esm.min.js';
console.log(ratio('fuzz', 'fuzzy'));
</script>
```
See the lite section below if you need the smallest possible file size.
See the lite section below if you need the smallest possible file size. If you need to support IE or node < v14 use v2.1.6 or earlier.

# Usage

Expand Down Expand Up @@ -84,9 +84,6 @@ fuzz.extractAsPromised("mr. harry hood", choices, options).then(res => {/* do st

// Cancel search

// For Node versions 14 and below and IE, use the legacy cancelToken option instead
// see the "Async and Cancellation" section below

const abortController = new AbortController();
options.abortController = abortController;

Expand Down Expand Up @@ -324,14 +321,12 @@ results = fuzz.extract(query, choices, options);
### Async and Cancellation

When using extractAsPromised or extractAsync, you might want to cancel the action before it has finished.
It can be done using `CancelToken` or `AbortController`.
It can be done using `AbortController`.

For performance, by default only every 256th loop will be async, but set `asyncLoopOffset` to change. It is most likely not worth changing this.

**AbortController**

[AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) is present in modern browsers and from node version `15+`. It is currently a standard way how to cancel running operations.

```js
// or use AbortController to cancel search
const abortController = new AbortController();
Expand All @@ -348,26 +343,6 @@ fuzz.extractAsPromised("gonna get aborted", choices, options)
abortController.abort();
```

**CancelToken**

For older browsers and node versions you can use cancel token. It is an in

```js
let cancelToken = { canceled: false };

options.cancelToken = cancelToken;
options.asyncLoopOffset = 64;

fuzz.extractAsPromised("gonna get canceled", choices, options)
.then(res => {/* do stuff */})
.catch((e) => {
if (e.message === 'canceled') console.log('I got canceled!')
});

// ...

cancelToken.canceled = true;
```

### Wildcards

Expand Down
Loading