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.0.1-b to 0.1.0

14

index.js
var Fuse = require('fuse.js');
var fuzzyFilter = function(value, options = {}) {
var fuzzyFilter = function(value, options) {
if (!options) {
options = {};
}
var defaultOptions = {

@@ -20,2 +23,11 @@ threshold: 0.4,

}
if (typeof val === 'object') {
var 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)
return temp;
}
return result.indexOf(idValues) !== -1;
}
return result.indexOf(key) !== -1;

@@ -22,0 +34,0 @@ };

4

package.json
{
"name": "fuzzy-array-filter",
"version": "0.0.1b",
"description": "A simple array fuzzy filtering",
"version": "0.1.0",
"description": "A simple fuzzy array prototype filter",
"main": "index.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -5,7 +5,9 @@ # fuzzy-array-filter

## How to use it
## How to use it : Simple
### Simple
### Basics
```javascript
use this wrapper with simple array `[val1, val2, ...]` il really (really) easy :
```JavaScript
ìmport fuzzyFilter from 'fuzzy-array-filter';

@@ -48,3 +50,3 @@

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

@@ -69,2 +71,99 @@

## How to use it : More complex
### Basics
When you use this wrapper with more complex data, make sure you have custom options.
you *MUST* fill the `id` and the `keys` options *AND* `id` *MUST* be one of the `keys` values.
In most of use cases `keys = [id, [whatever]]`.
### 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' },
];
const options = {
keys: ['names'],
id: 'names'
}
const filteredTab = tab.filter(fuzzyFilter('in', options))
console.log(filteredTab)
```
### Complex
```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' } },
];
const options2 = {
keys: ['names.first'],
id: 'names.first'
}
const filteredTab2 = tab2.filter(fuzzyFilter('in', options2))
console.log(filteredTab2)
```
### More complex
```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'] } },
];
const options3 = {
keys: ['names.first'],
id: 'names.first'
}
const filteredTab3 = tab3.filter(fuzzyFilter('in', options3))
console.log(filteredTab2)
```
## Dependencies

@@ -76,2 +175,2 @@

* It must filter more complex arrays
* An idea ?
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