mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2025-02-14 21:10:32 +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:
parent
074b4f0871
commit
a3be6c63a6
@ -10,14 +10,14 @@ import coreObjectEntries from 'core-js/library/fn/object/entries'
|
|||||||
*/
|
*/
|
||||||
function filterFromObject(obj, filter, { isInclusion = true } = {}) {
|
function filterFromObject(obj, filter, { isInclusion = true } = {}) {
|
||||||
if (filter && Array.isArray(filter)) {
|
if (filter && Array.isArray(filter)) {
|
||||||
return applyFilterOnObject(obj, isInclusion ? ((_, key) => coreIncludes(filter, key))
|
return applyFilterOnObject(obj, isInclusion ? (val => coreIncludes(filter, val))
|
||||||
: ((_, key) => !coreIncludes(filter, key)))
|
: (val => !coreIncludes(filter, val)))
|
||||||
} else if (filter && typeof filter === 'function') {
|
} else if (filter && typeof filter === 'function') {
|
||||||
// Flip the filter fn's return if it's for inclusion
|
// Flip the filter fn's return if it's for inclusion
|
||||||
return applyFilterOnObject(obj, isInclusion ? filter
|
return applyFilterOnObject(obj, isInclusion ? filter
|
||||||
: (...args) => !filter(...args))
|
: (...args) => !filter(...args))
|
||||||
} else {
|
} 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')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user