A function to filter all the things. Utilizes heavy memoization to quickly filter JSON string / object / array data in flexible ways.
npm install -S superfilter
none
import superfilter from 'superfilter'
const data = (
{ foo: 'bar'
, kung: (
{ fu: (
{ bar: 'foo'
, fuji: (
[ 1
, 2
, { coo: 'car'
, __type__: 'something'
}
]
)
}
)
}
)
}
)
const print = _ => console.info(JSON.stringify(_))
print(superfilter(data, 2))
// { kung: { fu: { fuji: [ 2 ] } } }
print(superfilter(data, `x => Object.keys(x).includes('foo')`)
// { foo: 'bar' }
The third parameter an options object to tweak how you filter:
optionName | type | description |
---|---|---|
filterKeys |
undefined , Array<string> |
Only keys supplied will be used in filtering values. (undefined => filter on all keys) |
walkKeys |
undefined , Array<string> |
Only keys supplied will be used in recursive traversal. (undefined => walk all paths) |
insertMarks |
undefined , boolean |
Inserts <mark></mark> tags around matching text. |