|
1 |
| -# Typescript Node Package Repository Template |
| 1 | +# 🤔 Fuzzy JSON Search |
2 | 2 |
|
3 |
| -> Create a new repo from this template to get started creating a Typescript npm package |
| 3 | +> VSCode style fuzzy search for JSON documents |
4 | 4 |
|
5 | 5 | <!--  -->
|
6 |
| -<!--  --> |
7 |
| -<!-- [](https://npmjs.com/@jsonhero/ts-node-package-template) --> |
8 |
| -<!-- [](https://packagephobia.com/result?p=@jsonhero/ts-node-package-template) --> |
| 6 | +<!--  --> |
| 7 | +<!-- [](https://npmjs.com/@jsonhero/fuzzy-json-search) --> |
| 8 | +<!-- [](https://packagephobia.com/result?p=@jsonhero/fuzzy-json-search) --> |
9 | 9 |
|
10 |
| -## Features |
| 10 | +## 🚀 Features |
11 | 11 |
|
12 |
| -- Written in typescript |
13 |
| -- Github workflows for running tests and publishing package to NPM on Github release |
14 |
| -- Rollup for building commonjs and esm compatible npm package |
15 |
| -- ts-node and ts-jest integration |
16 |
| -- Generate coverage badges |
17 |
| -- ESLint with Typescript and prettier support |
18 |
| -- Pre-commit hooks to format code with prettier and run ESLint |
| 12 | +- Use VSCode style fuzzy search on a JSON document |
| 13 | +- Searches through key names, path, raw values and formatted values |
19 | 14 |
|
20 |
| -## Usage |
| 15 | +## 💻 Usage |
21 | 16 |
|
22 |
| -Create a new repository from this template on Github with the [following instructions](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template) |
| 17 | +Install Fuzzy JSON Search |
| 18 | + |
| 19 | +```bash |
| 20 | +$ npm install --save @jsonhero/fuzzy-json-search |
| 21 | +``` |
| 22 | + |
| 23 | +The simplest way to search is to create an instance of `JSONHeroSearch` and pass it a JSON object: |
| 24 | + |
| 25 | +```typescript |
| 26 | +const response = await fetch("https://jsonplaceholder.typicode.com/todos"); |
| 27 | +const json = await response.json(); |
| 28 | + |
| 29 | +const searcher = new JSONHeroSearch(json); |
| 30 | + |
| 31 | +const results = searcher.search("user"); |
| 32 | +``` |
| 33 | + |
| 34 | +## API |
| 35 | + |
| 36 | +### `JSONHeroSearch.search(query: string)` |
| 37 | + |
| 38 | +Performs a fuzzy search against the entire document, ordering by score. Will only return results that score more than 0. |
| 39 | + |
| 40 | +#### Returns `Array<SearchResult<JSONHeroPath>>>` |
| 41 | + |
| 42 | +`SearchResult<JSONHeroPath>` has the following properties: |
| 43 | + |
| 44 | +##### `item` is a `JSONHeroPath` representing the path to the key |
| 45 | + |
| 46 | +##### `score` is an `ItemScore` |
| 47 | + |
| 48 | +##### `ItemScore` has the following properties |
| 49 | + |
| 50 | +##### `score` is a number, the higher the score the better a match |
| 51 | + |
| 52 | +##### `labelMatch` is an array of `Match` objects |
| 53 | + |
| 54 | +##### `descriptionMatch` is an array of `Match` objects |
| 55 | + |
| 56 | +##### `rawValueMatch` is an array of `Match` objects |
| 57 | + |
| 58 | +##### `formattedValueMatch` is an array of `Match` objects |
| 59 | + |
| 60 | +##### `Match` is type `{ start: number; end: number }` |
0 commit comments