0.2.0 • Published 3 years ago

@altipla/normalize-search v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

normalize-search

Normalize strings to search them client side.

Install

npm i @altipla/normalize-search

Usage

Basic usage

Import the package to have the pair of functions in scope:

import { prepareSearch, filterSearch } from '@altipla/normalize-search'

To filter a list of items you have first to prepare them:

// 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:

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:

import { normalizeSearch } from '@altipla/normalize-search'


let result1 = normalizeSearch('your text here')
let result2 = normalizeSearch([
  item.name,
  item.lastName,
])
0.2.0

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago