Skip to content

Filter an array of objects with using another object. extendable.

Notifications You must be signed in to change notification settings

pablomaurer/deep-array-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deep-array-filter

Filters an array of objects.

npm i deep-array-filter

Define your filter values:

the property $ will search in all keys.

let filterBy = {
    $: 'wayne',
    firstname: 'john',
    age: 18,
    address: {
        city: 'Basel'
    }
};

FilterTypes

Define type of your filters:

If not defined it will default to includes.

let filterTypes = {
    age: 'gt',
    address: { 
        city: 'gt' 
    }
}

Execute the filter

let filteredArr = filter(arr, filterBy, filterTypes)

Filters

Currently there are following filters defined:

  • includes - substring matching
  • gt - greater than
  • lt - less than

If you need more, open an Issue or send a PR.

extend filterTypes

If you need more or different filters, you can provide you custom compare functions.

let filterType = {
    age: 'customFilter'
};

let comparator = {
    customFilter: (value, filter) => {
        return value > filter;
    }
};

let filteredArr = filter(arr, filterBy, filterTypes, comparator)

About

Filter an array of objects with using another object. extendable.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published