diff options
| author | Vincent LE GOFF <g_n_s@hotmail.fr> | 2019-04-24 13:41:23 +0200 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-04-24 07:41:22 -0400 |
| commit | dcd01dd02530df0e799eb4227087680ffeb80d74 (patch) | |
| tree | 8cc1dec75dd17c326fea6d7fe471b7e7a31032f7 /util/deep_assign.ts | |
| parent | e1f7a60bb326f8299f339635c0738d28431afa0a (diff) | |
Eslint fixes (denoland/deno_std#356)
Make warnings fail
Original: https://github.com/denoland/deno_std/commit/4543b563a9a01c8c168aafcbfd9d4634effba7fc
Diffstat (limited to 'util/deep_assign.ts')
| -rw-r--r-- | util/deep_assign.ts | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/util/deep_assign.ts b/util/deep_assign.ts index 4857e18b5..77bf5e9b3 100644 --- a/util/deep_assign.ts +++ b/util/deep_assign.ts @@ -5,24 +5,26 @@ export function deepAssign(target: object, ...sources: object[]): object { if (!source || typeof source !== `object`) { return; } - Object.entries(source).forEach(([key, value]) => { - if (value instanceof Date) { - target[key] = new Date(value); - return; + Object.entries(source).forEach( + ([key, value]): 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], 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], value); - }); + ); } return target; } |
