UNPKG

@bemedev/decompose

Version:
28 lines (27 loc) 874 B
import { decompose } from "../decompose.js"; import { DEFAULT_OPTIONS } from "./constants.js"; //#region src/contexts/get.ts const _getByKey = (obj, key) => { return decompose.low(obj, DEFAULT_OPTIONS)[key]; }; /** * Retrieves a value from an object by a specified key. * @param obj The object to retrieve the value from * @param key The key to retrieve the value for, can be a nested key (e.g. 'a.b.c') * @returns The value associated with the specified key in the object * * @see {@linkcode Decompose} for more details on object decomposition. */ const getByKey = (obj, key) => _getByKey(obj, key); getByKey.low = getByKey; getByKey.typed = getByKey; getByKey.defined = getByKey; getByKey.options = (options) => (obj, key) => { return decompose.low(obj, { ...DEFAULT_OPTIONS, ...options })[key]; }; //#endregion export { getByKey }; //# sourceMappingURL=get.js.map