diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-10-09 17:22:22 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-10-09 17:22:22 -0400 |
commit | 93f7f00c956c14620ef031626f124b57397ca867 (patch) | |
tree | c5a9f536e79d2c8d2d02897511a9138acaf35394 /std/util/deep_assign.ts | |
parent | 28293acd9c12a94f5d769706291032e844c7b92b (diff) |
Run deno_std tests in github actions
Diffstat (limited to 'std/util/deep_assign.ts')
-rw-r--r-- | std/util/deep_assign.ts | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/std/util/deep_assign.ts b/std/util/deep_assign.ts index b1c9f9ac9..1dfc00a5b 100644 --- a/std/util/deep_assign.ts +++ b/std/util/deep_assign.ts @@ -8,24 +8,26 @@ 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; + 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!); } - 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; } |