Filter an array, map, object or set, with advanced options.
This module exports one function:
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
, thevalue
passed todecide
will be extracted from somewhere inside the original value by diving along the path given indive
as understood by moduleobjdive
. -
extract
: If set to a function, similar to thedive
option, extract the value to be filtered. Applies before potentialdive
-ing. -
argFmt
: (input format) What arguments to calldecide
with.-
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 ifinput
is a Map and you want to convert the output to JSON. -
'nobj'
: an Object withnull
prototype.
-
-
empty
: If set to something other thanundefined
, instead of an empty result, returnempty
.
see test/usage.mjs
- Needs more/better tests and docs.
ISC