UNPKG

@ngha/nested-value

Version:

nestedValue the value at `path` of `object`

34 lines (33 loc) 1.04 kB
export declare class NestedValueService { /** * nestedValue the value at `path` of `object`. If the resolved value is * `undefined`, the `defaultValue` is returned in its place. * * @param {Object} object The object to query. * @param {Array|string} path The path of the property to get. * @param defaultValue The value returned for `undefined` resolved values. * @example * * const object = { 'a': 'aa', 'b': [123, '456'], c: [{ d: '123', e: 'abc' }, { d: '456', e: 'def' }] }; * * nestedValue(object, 'a') * // => 'aa' * * nestedValue(object, 'b') * // => [123 , '456'] * * nestedValue(object, ['c[0].d']) * // => '123' * * nestedValue(object, ['c', [1], 'e']) * // => 'abc' * * nestedValue(object, ['c', [1], 'f']) * // => undefine * * nestedValue(object, ['c', [3], 'f'], 'default') * // => 'default' * */ nestedValue: (object: any, path: string | any[], defaultValue?: any) => any; }