MCPcopy Create free account
hub / github.com/chieapp/chie / deepAssign

Function deepAssign

src/util/object-utils.ts:5–24  ·  view source on GitHub ↗
(target: T, source: S)

Source from the content-addressed store, hash-verified

3
4// Like Object.assign but does a deep copy.
5export function deepAssign<T extends AnyObject, S extends AnyObject>(target: T, source: S): T {
6 if (!source)
7 return target;
8 for (const key of Object.keys(source)) {
9 const value = source[key];
10 if (typeof value == 'object' && value !== null) {
11 // eslint-disable-next-line no-prototype-builtins
12 if (target.hasOwnProperty(key) &&
13 typeof target[key as keyof T] == 'object' &&
14 target[key as keyof T] !== null) {
15 deepAssign(target[key], value);
16 } else {
17 target[key as keyof T] = value;
18 }
19 } else {
20 target[key as keyof T] = value;
21 }
22 }
23 return target;
24}
25
26// Like Object.assign but ignore null or undefined properties.
27export function nonNullAssign<T extends object, S extends object>(target: T, source: S): T {

Callers 4

createServiceMethod · 0.90
updateMessageFunction · 0.90
#refreshTokenMethod · 0.90
#onSubmitMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected