1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-11-22 01:36:56 +01:00

Fix sanitize array filter

The code for filtering with array has a small mistake,
where it checks if the "key" of the object is included in
the filter array instead of the "value" at that key.

Part of https://github.com/bigchaindb/js-bigchaindb-driver/issue/220
This commit is contained in:
Arjun Nemani 2018-07-19 21:09:41 +05:30
parent 074b4f0871
commit a3be6c63a6

View File

@ -10,14 +10,14 @@ import coreObjectEntries from 'core-js/library/fn/object/entries'
*/
function filterFromObject(obj, filter, { isInclusion = true } = {}) {
if (filter && Array.isArray(filter)) {
return applyFilterOnObject(obj, isInclusion ? ((_, key) => coreIncludes(filter, key))
: ((_, key) => !coreIncludes(filter, key)))
return applyFilterOnObject(obj, isInclusion ? (val => coreIncludes(filter, val))
: (val => !coreIncludes(filter, val)))
} else if (filter && typeof filter === 'function') {
// Flip the filter fn's return if it's for inclusion
return applyFilterOnObject(obj, isInclusion ? filter
: (...args) => !filter(...args))
} else {
throw new Error('The given filter is not an array or function. Exclude aborted')
throw new Error('The given filter is not an array or function. Filter aborted')
}
}