# @hyrious/fuzzy-match

> Match string like Sublime Text

Latest version **0.1.1** (published 2022-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hyrious/fuzzy-match
pnpm add @hyrious/fuzzy-match
yarn add @hyrious/fuzzy-match
bun add @hyrious/fuzzy-match
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2022-09-26 |
| First published | 2022-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | hyrious |
| Maintainers | hyrious |
| Keywords | string, match, fuzzy, search |

## Links

- npm: https://www.npmjs.com/package/@hyrious/fuzzy-match
- Repository: https://github.com/hyrious/fuzzy-match
- Homepage: https://github.com/hyrious/fuzzy-match#readme
- Issues: https://github.com/hyrious/fuzzy-match/issues
- npm.io page: https://npm.io/package/@hyrious/fuzzy-match

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2022-09-26
- 0.1.0 — 2022-09-26

## README

## @hyrious/fuzzy-match

> A string match function that help implementing fuzzy search like Sublime Text.

The algorithm is derived from [this C implementation of fts_fuzzy_match](https://github.com/tajmone/fuzzy-search/tree/master/fts_fuzzy_match/0.2.0/c).

## Install

```
npm add @hyrious/fuzzy-match
```

## Usage

```js
import { match, match_trace } from "@hyrious/fuzzy-match";

match("th", "tth-hash");
// => 45 (score, maybe negative)

match("not found", "string");
// => -Infinity

// Match with backtrack, useful when we want to highlight the matching chars.
match_trace("th", "tth-hash");
// => { score: 45, stops: [0, 4] }

match_trace("not found", "string");
// => null
```

### Possible Fuzzy Search Implementation

```js
import { match } from "@hyrious/fuzzy-match";

function search(text, list) {
  return list
    .map((item) => ({
      item,
      score: match(text, item),
    }))
    .filter(({ score }) => score > -Infinity)
    .sort((a, b) => b.score - a.score);
}
```

## License

MIT @ [hyrious](https://github.com/hyrious)

---
_Source: https://npm.io/package/@hyrious/fuzzy-match · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
