0.2.0 • Published 4 years ago
filter-container-entries-pmb v0.2.0
filter-container-entries-pmb
Filter an array, map, object or set, with advanced options.
API
This module exports one function:
makeFilter(opt)
Returns a filter function that expects one argument, input.
opt is an optional options object that supports these optional keys:
decide: The function that decides what to keep. It will be called with arguments according to optionargFmt. Default: the buil-inBoolean.negate: If true-y, negate the results ofdecide.dive: If set to something other thanundefined, thevaluepassed todecidewill be extracted from somewhere inside the original value by diving along the path given indiveas understood by moduleobjdive.extract: If set to a function, similar to thediveoption, extract the value to be filtered. Applies before potentialdive-ing.argFmt: (input format) What arguments to calldecidewith.undefined(default):(value, key, input)'entries':(entry, index, input)whereentry = [key, value].
outFmt: (output format) How to deliver the results:undefined(default): same container type as input was.'entries': array of[key, value]pairs.'keys': array of matching keys frominput'values': array of matching values frominput'dict': plain Object. Useful ifinputis a Map and you want to convert the output to JSON.'nobj': an Object withnullprototype.
empty: If set to something other thanundefined, instead of an empty result, returnempty.
Usage
see test/usage.mjs
Known issues
- Needs more/better tests and docs.
License
ISC