UNPKG

@n3okill/utils

Version:
43 lines 1.86 kB
"use strict"; /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.deepFillIn = deepFillIn; const isPlainObject_1 = require("../type/isPlainObject"); /** * Fill non-existent properties in the first object with the other objects * @param args Objects to fill * @returns The first object filled with the new properties */ function deepFillIn(...args) { if (args.length === 0) return {}; const target = args.shift(); for (const obj of args) { for (const [key, value] of Object.entries(obj)) { if (!Object.prototype.hasOwnProperty.call(target, key)) { // eslint-disable-next-line security/detect-object-injection target[key] = value; } else if ((0, isPlainObject_1.isPlainObject)(target) && (0, isPlainObject_1.isPlainObject)(value)) { // eslint-disable-next-line security/detect-object-injection deepFillIn(target[key], value); } } } /*args.forEach((obj): void => { Object.keys(obj).forEach((key): void => { if (!Object.prototype.hasOwnProperty.call(target, key)) { // eslint-disable-next-line security/detect-object-injection target[key] = (obj as any)[key]; // eslint-disable-next-line security/detect-object-injection } else if (isPlainObject(target) && isPlainObject((obj as any)[key])) { // eslint-disable-next-line security/detect-object-injection deepFillIn(target[key], (obj as any)[key]); } }); });*/ return target; } //# sourceMappingURL=deepFillIn.js.map