diff options
Diffstat (limited to 'util/deep_assign.ts')
-rw-r--r-- | util/deep_assign.ts | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/util/deep_assign.ts b/util/deep_assign.ts index 1dfc00a5b..b1c9f9ac9 100644 --- a/util/deep_assign.ts +++ b/util/deep_assign.ts @@ -8,26 +8,24 @@ export function deepAssign( if (!source || typeof source !== `object`) { return; } - Object.entries(source).forEach( - ([key, value]: [string, unknown]): void => { - if (value instanceof Date) { - target[key] = new Date(value); - return; - } - if (!value || typeof value !== `object`) { - target[key] = value; - return; - } - if (Array.isArray(value)) { - target[key] = []; - } - // value is an Object - if (typeof target[key] !== `object` || !target[key]) { - target[key] = {}; - } - deepAssign(target[key] as Record<string, unknown>, value!); + Object.entries(source).forEach(([key, value]: [string, unknown]): void => { + if (value instanceof Date) { + target[key] = new Date(value); + return; } - ); + if (!value || typeof value !== `object`) { + target[key] = value; + return; + } + if (Array.isArray(value)) { + target[key] = []; + } + // value is an Object + if (typeof target[key] !== `object` || !target[key]) { + target[key] = {}; + } + deepAssign(target[key] as Record<string, unknown>, value!); + }); } return target; } |