UNPKG

rambda

Version:

Lightweight faster alternative to Ramda

22 lines (17 loc) 485 B
export function pick(propsToPick, obj){ if (arguments.length === 1) return _obj => pick(propsToPick, _obj) if (obj === null || obj === undefined){ return undefined } const keys = typeof propsToPick === 'string' ? propsToPick.split(',') : propsToPick const willReturn = {} let counter = 0 while (counter < keys.length){ if (keys[ counter ] in obj){ willReturn[ keys[ counter ] ] = obj[ keys[ counter ] ] } counter++ } return willReturn }