blob: b25a71ac4fd5ec47a2b2ae58c1bca9a19c76c06b [file] [log] [blame] [edit]
import { createPath } from './_internals/createPath.js'
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 = createPath(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
}