UNPKG

@modernpoacher/halacious

Version:
21 lines (18 loc) 460 B
function reduce (accumulator, fieldName) { return ( fieldName in accumulator // Reflect.has(accumulator, fieldName) ? accumulator[fieldName] // Reflect.get(accumulator, fieldName) : accumulator ) } /** * Previously `reach` */ export default function getFieldValueByPath (path = '', context = {}) { const fieldNames = String(path ?? '').split('.') return ( fieldNames .filter(Boolean) .reduce(reduce, context) ) }