1.0.8 • Published 4 years ago

multiple-array-filter v1.0.8

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

NPM Version NPM Downloads NPM License

A simple way to filter an array with multiple filters

To install :

$ npm i multiple-array-filter

or

$ yarn add multiple-array-filter

Usage:

This library was made to help you to filter an array with a lot of filters, imagine that you have an app with a flatlist that contains a list of user, so to each user there is a lot of fieldes to search to.

You can make a single filter field and than search into each user's field with this library. Another approach is creating dinamics filters where each filter is a field of your user and than you pass this to the library.

'use strict'

const { filterAndSortArray } = require('multiple-array-filter');

const items = [
  { name: 'Steve Jobs', id: 1 },
  { name: 'Elon Musk', id: 2 },
  { name: 'Robert C. Martin', id: 3 },
  { name: 'Bill Gates', id: 4 },
]

const filters = [
  { field: 'name', search: ['bil', 'job'] },
  { field: 'id', search: 3 },
]

const filtered_array = filterAndSortArray(items, filters, 'id');

console.log(filtered_array);
/**
 * [
 *  { name: 'Steve Jobs', id: 1 },
 *  { name: 'Robert C. Martin', id: 3 },
 *  { name: 'Bill Gates', id: 4 }
 * ]
 */
1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago