Browse Source

feat: add Node instance control to deepMerge

pull/6155/head
muhammedaltug 6 years ago
parent
commit
a8e488f5db
  1. 8
      npm/ng-packs/packages/core/src/lib/utils/common-utils.ts
  2. 15
      npm/ng-packs/packages/core/src/lib/utils/object-utils.ts

8
npm/ng-packs/packages/core/src/lib/utils/common-utils.ts

@ -27,3 +27,11 @@ export function isArray(obj) {
export function isObjectAndNotArray(obj) {
return isObject(obj) && !isArray(obj);
}
export function isNode(obj) {
return obj instanceof Node;
}
export function isObjectAndNotArrayNotNode(obj) {
return isObjectAndNotArray(obj) && !isNode(obj);
}

15
npm/ng-packs/packages/core/src/lib/utils/object-utils.ts

@ -1,7 +1,14 @@
import { isObjectAndNotArray, isNullOrUndefined, exists, isArray, isObject } from './common-utils';
import {
exists,
isArray,
isNode,
isNullOrUndefined,
isObject,
isObjectAndNotArrayNotNode,
} from './common-utils';
export function deepMerge(target, source) {
if (isObjectAndNotArray(target) && isObjectAndNotArray(source)) {
if (isObjectAndNotArrayNotNode(target) && isObjectAndNotArrayNotNode(source)) {
return deepMergeRecursively(target, source);
} else if (isNullOrUndefined(target) && isNullOrUndefined(source)) {
return {};
@ -17,7 +24,9 @@ function deepMergeRecursively(target, source) {
isArray(target) ||
isArray(source) || // at least one array
!isObject(target) ||
!isObject(source); // at least one not an object
!isObject(source) || // at least one not an object
isNode(target) ||
isNode(source); // at least one node
/**
* if we will not recurse any further,

Loading…
Cancel
Save