UNPKG

@bemedev/decompose

Version:
30 lines (29 loc) 853 B
import { DEFAULT_FLAT_OPTIONS } from "./constants/objects.js"; //#region src/flatByKey.ts const _flat = (val, omitKey, options, path = "") => { const _options = { ...DEFAULT_FLAT_OPTIONS, ...options }; const { [omitKey]: recursives, ...rest } = val; const check = _options.children; let out = {}; out[path === "" ? _options.sep : path] = check ? val : rest; if (recursives) { for (const key in recursives) if (Object.prototype.hasOwnProperty.call(recursives, key)) { const element = recursives[key]; const inner = _flat(element, omitKey, options, `${path}${_options.sep}${key}`); out = { ...out, ...inner }; } } return out; }; const flatByKey = (val, key, options) => _flat(val, key, options); flatByKey.low = _flat; flatByKey.strict = _flat; //#endregion export { flatByKey }; //# sourceMappingURL=flatByKey.js.map