https://github.com/luqmanoop/use-command-score
Tiny, fast fuzzy ⚡️earch for React applications
https://github.com/luqmanoop/use-command-score
autcomplete filter fuzzy-matching fuzzy-search list react search typescript
Last synced: about 2 months ago
JSON representation
Tiny, fast fuzzy ⚡️earch for React applications
- Host: GitHub
- URL: https://github.com/luqmanoop/use-command-score
- Owner: luqmanoop
- License: mit
- Created: 2023-05-15T07:22:27.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-18T13:23:08.000Z (about 3 years ago)
- Last Synced: 2025-10-06T23:40:53.823Z (8 months ago)
- Topics: autcomplete, filter, fuzzy-matching, fuzzy-search, list, react, search, typescript
- Language: TypeScript
- Homepage: https://use-command-score.vercel.app
- Size: 34.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
- License: license
Awesome Lists containing this project
README
# use-command-score
> Tiny, fast fuzzy ⚡️earch for React applications
Live demo https://use-command-score.vercel.app
## Install
```sh
npm install use-command-score
```
## Usage
```ts
import { useCommandScore } from "use-command-score";
useCommandScore(needle, haystack, options);
```
## Examples
Search array of strings
```ts
useCommandScore("vsc", ["Vim", "Google chrome", "Visual studio code"]); // ['Visual studio code']
```
Search array of objects & limit result [Live demo](https://use-command-score.vercel.app/?path=/story/moviesfuzzysearch--with-limit)
```ts
useCommandScore("hger", movies, {
limit: 3,
keys: ["title", "meta.actors", "meta.director"]
});
```
## API
`useCommandScore(needle, haystack, options)`
### needle
Search query
Type: `string`
Required: `true`
### haystack
Array of items to search
Type: `Array`
Required: `true`
### options
Type: `object`
Required: `false`
#### options.keys
Object key paths in `haystack`. The value of the key paths will be matched against `needle`
Type: `Array`
Required: `false`
```ts
const data = [
{ name: "a", address: { code: "123" } },
{ name: "b", address: { code: "456" } }
];
useCommandScore("4", data, { keys: ["name", "address.code"] });
```
#### options.limit
Limits the total results returned
Type: `number`
Required: `false`
```ts
useCommandScore(needle, haystack, { limit: 5 });
```
## Related
- [command score](https://github.com/superhuman/command-score)