Socket
Socket
Sign inDemoInstall

fuzzy-array-filter

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fuzzy-array-filter - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

.babelrc

35

index.js

@@ -1,24 +0,19 @@

var Fuse = require('fuse.js');
import Fuse from 'fuse.js';
var fuzzyFilter = function(value, options) {
export default (value = null, options = {}) => {
if (!value) {
return function() {
return true;
}
return () => true;
}
if (!options) {
options = {};
}
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) {

@@ -29,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;

@@ -40,4 +35,2 @@ }

};
}
module.exports = fuzzyFilter;
};

12

package.json
{
"name": "fuzzy-array-filter",
"version": "0.1.2",
"version": "0.1.3",
"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"
}
}

@@ -19,3 +19,3 @@ # fuzzy-array-filter

```JavaScript
```js
ìmport fuzzyFilter from 'fuzzy-array-filter';

@@ -40,3 +40,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' ]

@@ -59,3 +59,3 @@

```JavaScript
```js
ìmport fuzzyFilter from 'fuzzy-array-filter';

@@ -69,3 +69,3 @@

console.log(array.filter(fuzzySearch('new orleans', options)));
console.log(array.filter(fuzzyFilter('new orleans', options)));
// => []

@@ -86,23 +86,23 @@

When you use this wrapper with more complex data structure, make sure you have provided some custom options.
You **MUST** fill the `id` and the `keys` options **AND** `id` **MUST** be one of the `keys` values.
You **MUST** fill the `id` and the `keys` options.
In most of use cases `keys = [id, [whatever]]`.
`id` option is a single value. It can represent anything, like a string or a number.
### Simple complex
```JavaScript
const tab = [
{names: 'Edwina' },
{names: 'Augusta' },
{names: 'Lina' },
{names: 'Ware' },
{names: 'Kim' },
{names: 'Nita' },
{names: 'Garrett' },
{names: 'Concepcion' },
{names: 'Laverne' },
{names: 'Alford' },
{names: 'Jill' },
{names: 'Reed' },
{names: 'Shaw' },
```js
const array = [
{ uniqueValue: 1, names: 'Edwina' },
{ uniqueValue: 2, names: 'Augusta' },
{ uniqueValue: 3, names: 'Lina' },
{ uniqueValue: 4, names: 'Ware' },
{ uniqueValue: 5, names: 'Kim' },
{ uniqueValue: 6, names: 'Nita' },
{ uniqueValue: 7, names: 'Garrett' },
{ uniqueValue: 8, names: 'Concepcion' },
{ uniqueValue: 9, names: 'Laverne' },
{ uniqueValue: 10, names: 'Alford' },
{ uniqueValue: 11, names: 'Jill' },
{ uniqueValue: 12, names: 'Reed' },
{ uniqueValue: 13, names: 'Shaw' },
];

@@ -112,7 +112,7 @@

keys: ['names'],
id: 'names'
id: 'uniqueValue'
}
const filteredTab = tab.filter(fuzzyFilter('in', options))
console.log(filteredTab)
const filteredArray = array.filter(fuzzyFilter('in', options))
console.log(filteredArray)

@@ -123,26 +123,26 @@ ```

```JavaScript
const tab2 = [
{names: { first: 'Edwina' } },
{names: { first: 'Augusta' } },
{names: { first: 'Lina' } },
{names: { first: 'Ware' } },
{names: { first: 'Kim' } },
{names: { first: 'Nita' } },
{names: { first: 'Garrett' } },
{names: { first: 'Concepcion' } },
{names: { first: 'Laverne' } },
{names: { first: 'Alford' } },
{names: { first: 'Jill' } },
{names: { first: 'Reed' } },
{names: { first: 'Shaw' } },
```js
const array2 = [
{ id: 1, names: { first: 'Edwina', last:'random' } },
{ id: 2, names: { first: 'Augusta', last:'random' } },
{ id: 3, names: { first: 'Lina', last:'random' } },
{ id: 4, names: { first: 'Ware', last:'random' } },
{ id: 5, names: { first: 'Kim', last:'random' } },
{ id: 6, names: { first: 'Nita', last:'random' } },
{ id: 7, names: { first: 'Garrett', last:'random' } },
{ id: 8, names: { first: 'Concepcion', last:'random' } },
{ id: 9, names: { first: 'Laverne', last:'random' } },
{ id: 10, names: { first: 'Alford', last:'random' } },
{ id: 11, names: { first: 'Jill', last:'random' } },
{ id: 12, names: { first: 'Reed', last:'random' } },
{ id: 13, names: { first: 'Shaw', last:'random' } },
];
const options2 = {
keys: ['names.first'],
id: 'names.first'
keys: ['names.first', 'names.last'],
id: 'id'
}
const filteredTab2 = tab2.filter(fuzzyFilter('in', options2))
console.log(filteredTab2)
const filteredArray2 = array2.filter(fuzzyFilter('in', options2))
console.log(filteredArray2)

@@ -153,17 +153,17 @@ ```

```JavaScript
const tab3 = [
{names: { first: ['Edwina'] } },
{names: { first: ['Augusta'] } },
{names: { first: ['Lina'] } },
{names: { first: ['Ware'] } },
{names: { first: ['Kim'] } },
{names: { first: ['Nita'] } },
{names: { first: ['Garrett'] } },
{names: { first: ['Concepcion'] } },
{names: { first: ['Laverne'] } },
{names: { first: ['Alford'] } },
{names: { first: ['Jill'] } },
{names: { first: ['Reed'] } },
{names: { first: ['Shaw'] } },
```js
const array3 = [
{ id: 1, names: { first: ['Edwina'], last:['random'] } },
{ id: 2, names: { first: ['Augusta'], last:['random'] } },
{ id: 3, names: { first: ['Lina'], last:['random'] } },
{ id: 4, names: { first: ['Ware'], last:['random'] } },
{ id: 5, names: { first: ['Kim'], last:['random'] } },
{ id: 6, names: { first: ['Nita'], last:['random'] } },
{ id: 7, names: { first: ['Garrett'], last:['random'] } },
{ id: 8, names: { first: ['Concepcion'], last:['random'] } },
{ id: 9, names: { first: ['Laverne'], last:['random'] } },
{ id: 10, names: { first: ['Alford'], last:['random'] } },
{ id: 11, names: { first: ['Jill'], last:['random'] } },
{ id: 12, names: { first: ['Reed'], last:['random'] } },
{ id: 13, names: { first: ['Shaw'], last:['random'] } },
];

@@ -173,7 +173,7 @@

keys: ['names.first'],
id: 'names.first'
id: 'id'
}
const filteredTab3 = tab3.filter(fuzzyFilter('in', options3))
console.log(filteredTab2)
const filteredArray3 = array3.filter(fuzzyFilter('in', options3))
console.log(filteredArray3)

@@ -180,0 +180,0 @@ ```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc