Skip to main content
Module

x/rambda/source/path.js

Faster and smaller alternative to Ramda
Go to Latest
File
export function path(pathInput, obj) { if (arguments.length === 1) return _obj => path(pathInput, _obj)
if (obj === null || obj === undefined) { return undefined } let willReturn = obj let counter = 0
const pathArrValue = typeof pathInput === 'string' ? pathInput.split('.') : pathInput
while (counter < pathArrValue.length) { if (willReturn === null || willReturn === undefined) { return undefined } if (willReturn[pathArrValue[counter]] === null) return undefined
willReturn = willReturn[pathArrValue[counter]] counter++ }
return willReturn}