rambdax
Version:
Extended version of Rambda - a lightweight, faster alternative to Ramda
24 lines (19 loc) • 582 B
JavaScript
export function pickAll(propsToPick, obj){
if (arguments.length === 1) return _obj => pickAll(propsToPick, _obj)
if (obj === null || obj === undefined){
return undefined
}
const keysValue =
typeof propsToPick === 'string' ? propsToPick.split(',') : propsToPick
const willReturn = {}
let counter = 0
while (counter < keysValue.length){
if (keysValue[ counter ] in obj){
willReturn[ keysValue[ counter ] ] = obj[ keysValue[ counter ] ]
} else {
willReturn[ keysValue[ counter ] ] = undefined
}
counter++
}
return willReturn
}