Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/altipla-consulting/normalize-search
[GERRIT] Normalize strings to search them client side.
https://github.com/altipla-consulting/normalize-search
Last synced: about 1 month ago
JSON representation
[GERRIT] Normalize strings to search them client side.
- Host: GitHub
- URL: https://github.com/altipla-consulting/normalize-search
- Owner: altipla-consulting
- License: mit
- Created: 2021-05-17T14:49:28.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-07T22:36:36.000Z (over 3 years ago)
- Last Synced: 2024-09-20T12:17:51.614Z (4 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@altipla/normalize-search
- Size: 557 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# normalize-search
Normalize strings to search them client side.
## Install
```sh
npm i @altipla/normalize-search
```## Usage
### Basic usage
Import the package to have the pair of functions in scope:
```js
import { prepareSearch, filterSearch } from '@altipla/normalize-search'
```To filter a list of items you have first to prepare them:
```js
// From the server or any other data source
let items = [
{name: 'foo', lastName: 'bar'},
{name: 'baz', lastName: 'qux'},
]items.forEach(item => {
prepareSearch(item, [
item.name,
item.lastName,
// ... any other thing you want to link to the item
])
})
```Then you can generate a new function to filter the items with the user input:
```js
let userInput = 'qu' // obtained from your user interface
let filteredItems = items.filter(filterSearch(userInput))
```### Custom normalization
If you want to prepare a custom search of any kind where you need the normalized text call `normalizeSearch`:
```js
import { normalizeSearch } from '@altipla/normalize-search'let result1 = normalizeSearch('your text here')
let result2 = normalizeSearch([
item.name,
item.lastName,
])
```