Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ruanyl/array-fuzzy-match
https://github.com/ruanyl/array-fuzzy-match
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ruanyl/array-fuzzy-match
- Owner: ruanyl
- License: mit
- Created: 2017-02-22T15:39:05.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-02T11:31:30.000Z (almost 6 years ago)
- Last Synced: 2024-12-05T14:47:34.250Z (about 1 month ago)
- Language: TypeScript
- Size: 44.9 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# array fuzzy match
```
npm i array-fuzzy-match
``````
import isMatch from 'array-fuzzy-match'test('should return true if matches words', t => {
const arr = ['zhong', 'guo', 'zhong', 'che']
t.true(isMatch(arr, 'zhong'))
t.true(isMatch(arr, 'guo'))
t.true(isMatch(arr, 'zhongg'))
t.true(isMatch(arr, 'guozhong'))
})test('should return true if matches words case-insensitive', t => {
const arr = ['zhong', 'guo', 'zhong', 'che']
t.true(isMatch(arr, 'Zhong'))
t.true(isMatch(arr, 'GUO'))
t.true(isMatch(arr, 'ZHONGG'))
t.true(isMatch(arr, 'guoZhong'))
})test('should matches first letter of each word from beginning', t => {
const arr = ['zhong', 'guo', 'zhong', 'che']
t.true(isMatch(arr, 'ZG'))
t.true(isMatch(arr, 'ZGZC'))
t.false(isMatch(arr, 'GZ'))
})test('should match from the beginning', t => {
const arr = ['zhong', 'guo', 'zhong', 'che']
const config = { wordFromStart: true }
t.true(isMatch(arr, 'zhong', config))
t.false(isMatch(arr, 'guo', config))
t.true(isMatch(arr, 'zhongg', config))
t.false(isMatch(arr, 'guozhong', config))
})test('should matches first letter of each word', t => {
const arr = ['zhong', 'guo', 'zhong', 'che']
const config = { letterFromStart: false }
t.true(isMatch(arr, 'ZG', config))
t.true(isMatch(arr, 'ZGZC', config))
t.true(isMatch(arr, 'GZ', config))
})
```