fuzzy-array-filter
Advanced tools
Comparing version 0.1.1 to 0.1.2-test
32
index.js
@@ -1,19 +0,19 @@ | ||
var Fuse = require('fuse.js'); | ||
import Fuse from 'fuse.js'; | ||
var fuzzyFilter = function(value, options) { | ||
if (!options) { | ||
options = {}; | ||
export default (value = null, options = {}) => { | ||
if (!value) { | ||
return () => true; | ||
} | ||
var defaultOptions = { | ||
threshold: 0.4, | ||
const defaultOptions = { | ||
distance: 100, | ||
keys: [], | ||
location: 0, | ||
distance: 100, | ||
maxPatternLength: 32, | ||
keys: [] | ||
threshold: 0.4, | ||
}; | ||
var fuse = null; | ||
var result = null; | ||
let fuse = null; | ||
let result = null; | ||
return function(val, key, array) { | ||
return (val, key, array) => { | ||
if (!fuse || !result) { | ||
@@ -24,6 +24,6 @@ fuse = new Fuse(array, Object.assign(defaultOptions, options)) | ||
if (typeof val === 'object') { | ||
var idValues = val; | ||
options.id.split('.').forEach(key => idValues = idValues[key]) | ||
let idValues = val; | ||
options.id.split('.').forEach(key => (idValues = idValues[key])) | ||
if (Array.isArray(idValues)) { | ||
var temp = idValues.reduce((prev, idValue) => (result.indexOf(idValue) !== -1 || prev), false) | ||
let temp = idValues.reduce((prev, idValue) => (result.indexOf(idValue) !== -1 || prev), false) | ||
return temp; | ||
@@ -35,4 +35,2 @@ } | ||
}; | ||
} | ||
module.exports = fuzzyFilter; | ||
}; |
{ | ||
"name": "fuzzy-array-filter", | ||
"version": "0.1.1", | ||
"version": "0.1.2-test", | ||
"description": "A simple fuzzy array prototype filter", | ||
"main": "index.js", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "./node_modules/.bin/babel -d dist index.js", | ||
"postinstall": "npm run build" | ||
}, | ||
@@ -26,3 +28,7 @@ "repository": { | ||
"fuse.js": "2.5.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.0", | ||
"babel-preset-es2015": "^6.24.0" | ||
} | ||
} |
@@ -13,3 +13,3 @@ # fuzzy-array-filter | ||
## How to use it : Simple | ||
## How to use it : Simple data structure | ||
@@ -20,3 +20,3 @@ ### Basics | ||
```JavaScript | ||
```js | ||
ìmport fuzzyFilter from 'fuzzy-array-filter'; | ||
@@ -41,3 +41,3 @@ | ||
console.log(array.filter(fuzzySearch('new orleans'))); | ||
console.log(array.filter(fuzzyFilter('new orleans'))); | ||
// => [ 'There is a house in New Orleans', 'Down in New Orleans' ] | ||
@@ -60,3 +60,3 @@ | ||
```JavaScript | ||
```js | ||
ìmport fuzzyFilter from 'fuzzy-array-filter'; | ||
@@ -70,3 +70,3 @@ | ||
console.log(array.filter(fuzzySearch('new orleans', options))); | ||
console.log(array.filter(fuzzyFilter('new orleans', options))); | ||
// => [] | ||
@@ -93,4 +93,4 @@ | ||
```JavaScript | ||
const tab = [ | ||
```js | ||
const array = [ | ||
{names: 'Edwina' }, | ||
@@ -116,4 +116,4 @@ {names: 'Augusta' }, | ||
const filteredTab = tab.filter(fuzzyFilter('in', options)) | ||
console.log(filteredTab) | ||
const filteredArray = array.filter(fuzzyFilter('in', options)) | ||
console.log(filteredArray) | ||
@@ -124,4 +124,4 @@ ``` | ||
```JavaScript | ||
const tab2 = [ | ||
```js | ||
const array2 = [ | ||
{names: { first: 'Edwina' } }, | ||
@@ -147,4 +147,4 @@ {names: { first: 'Augusta' } }, | ||
const filteredTab2 = tab2.filter(fuzzyFilter('in', options2)) | ||
console.log(filteredTab2) | ||
const filteredArray2 = array2.filter(fuzzyFilter('in', options2)) | ||
console.log(filteredArray2) | ||
@@ -155,4 +155,4 @@ ``` | ||
```JavaScript | ||
const tab3 = [ | ||
```js | ||
const array3 = [ | ||
{names: { first: ['Edwina'] } }, | ||
@@ -178,4 +178,4 @@ {names: { first: ['Augusta'] } }, | ||
const filteredTab3 = tab3.filter(fuzzyFilter('in', options3)) | ||
console.log(filteredTab2) | ||
const filteredArray3 = array3.filter(fuzzyFilter('in', options3)) | ||
console.log(filteredArray2) | ||
@@ -182,0 +182,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
17725
6
2
1