Skip to content

Commit 38c5f8f

Browse files
committed
Initial commit
1 parent 1f89188 commit 38c5f8f

17 files changed

+7903
-2356
lines changed

README.md

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,60 @@
1-
# Typescript Node Package Repository Template
1+
# 🤔 Fuzzy JSON Search
22

3-
> Create a new repo from this template to get started creating a Typescript npm package
3+
> VSCode style fuzzy search for JSON documents
44
55
<!-- ![Coverage lines](./badges/badge-lines.svg) -->
6-
<!-- ![Tests](https://github.com/jsonhero-io/ts-node-package-template/actions/workflows/test.yml/badge.svg?branch=main) -->
7-
<!-- [![Downloads](https://img.shields.io/npm/dm/%40jsonhero%2Fts-node-package-template.svg)](https://npmjs.com/@jsonhero/ts-node-package-template) -->
8-
<!-- [![Install size](https://packagephobia.com/badge?p=%40jsonhero%2Fts-node-package-template)](https://packagephobia.com/result?p=@jsonhero/ts-node-package-template) -->
6+
<!-- ![Tests](https://github.com/jsonhero-io/fuzzy-json-search/actions/workflows/test.yml/badge.svg?branch=main) -->
7+
<!-- [![Downloads](https://img.shields.io/npm/dm/%40jsonhero%2Ffuzzy-json-search.svg)](https://npmjs.com/@jsonhero/fuzzy-json-search) -->
8+
<!-- [![Install size](https://packagephobia.com/badge?p=%40jsonhero%2Ffuzzy-json-search)](https://packagephobia.com/result?p=@jsonhero/fuzzy-json-search) -->
99

10-
## Features
10+
## 🚀 Features
1111

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
1914

20-
## Usage
15+
## 💻 Usage
2116

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

Comments
 (0)