@domql/utils 2.5.17 → 2.5.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/object.js +8 -3
- package/object.js +8 -4
- package/package.json +5 -2
package/dist/cjs/object.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(object_exports, {
|
|
|
23
23
|
deepCloneExclude: () => deepCloneExclude,
|
|
24
24
|
deepContains: () => deepContains,
|
|
25
25
|
deepDestringify: () => deepDestringify,
|
|
26
|
+
deepDiff: () => deepDiff,
|
|
26
27
|
deepMerge: () => deepMerge,
|
|
27
28
|
deepStringify: () => deepStringify,
|
|
28
29
|
detachFunctionsFromObject: () => detachFunctionsFromObject,
|
|
@@ -48,6 +49,7 @@ var import_globals = require("./globals.js");
|
|
|
48
49
|
var import_types = require("./types.js");
|
|
49
50
|
var import_array = require("./array.js");
|
|
50
51
|
var import_string = require("./string.js");
|
|
52
|
+
var import_deep_object_diff = require("deep-object-diff");
|
|
51
53
|
const exec = (param, element, state, context) => {
|
|
52
54
|
if ((0, import_types.isFunction)(param)) {
|
|
53
55
|
return param(
|
|
@@ -126,7 +128,7 @@ const deepCloneExclude = (obj, excludeFrom = []) => {
|
|
|
126
128
|
const mergeArrayExclude = (arr, excl = []) => {
|
|
127
129
|
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
128
130
|
};
|
|
129
|
-
const deepClone = (obj, excludeFrom = []) => {
|
|
131
|
+
const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
|
|
130
132
|
const o = (0, import_types.isArray)(obj) ? [] : {};
|
|
131
133
|
for (const prop in obj) {
|
|
132
134
|
if (prop === "__proto__")
|
|
@@ -134,11 +136,13 @@ const deepClone = (obj, excludeFrom = []) => {
|
|
|
134
136
|
if (excludeFrom.includes(prop) || prop.startsWith("__"))
|
|
135
137
|
continue;
|
|
136
138
|
let objProp = obj[prop];
|
|
139
|
+
if (cleanUndefined && (0, import_types.isUndefined)(objProp))
|
|
140
|
+
continue;
|
|
137
141
|
if (prop === "extend" && (0, import_types.isArray)(objProp)) {
|
|
138
142
|
objProp = (0, import_array.mergeArray)(objProp);
|
|
139
143
|
}
|
|
140
144
|
if ((0, import_types.isObjectLike)(objProp)) {
|
|
141
|
-
o[prop] = deepClone(objProp, excludeFrom);
|
|
145
|
+
o[prop] = deepClone(objProp, excludeFrom, cleanUndefined);
|
|
142
146
|
} else
|
|
143
147
|
o[prop] = objProp;
|
|
144
148
|
}
|
|
@@ -192,7 +196,7 @@ const objectToString = (obj, indent = 0) => {
|
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
str += `${spaces} ]`;
|
|
195
|
-
} else if ((0, import_types.
|
|
199
|
+
} else if ((0, import_types.isObjectLike)(value)) {
|
|
196
200
|
str += objectToString(value, indent + 1);
|
|
197
201
|
} else if ((0, import_types.isString)(value)) {
|
|
198
202
|
str += (0, import_string.stringIncludesAny)(value, ["\n", "'"]) ? `\`${value}\`` : `'${value}'`;
|
|
@@ -326,6 +330,7 @@ const diff = (original, objToDiff, cache = {}) => {
|
|
|
326
330
|
}
|
|
327
331
|
return cache;
|
|
328
332
|
};
|
|
333
|
+
const deepDiff = import_deep_object_diff.diff;
|
|
329
334
|
const overwrite = (element, params, excludeFrom = []) => {
|
|
330
335
|
const { ref } = element;
|
|
331
336
|
const changes = {};
|
package/object.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { window } from './globals.js'
|
|
4
|
-
import { isFunction, isObjectLike, isObject, isArray, isString, is } from './types.js'
|
|
4
|
+
import { isFunction, isObjectLike, isObject, isArray, isString, is, isUndefined } from './types.js'
|
|
5
5
|
import { mergeAndCloneIfArray, mergeArray } from './array.js'
|
|
6
6
|
import { stringIncludesAny } from './string.js'
|
|
7
|
+
import { diff as deepObjectDiff } from 'deep-object-diff'
|
|
7
8
|
|
|
8
9
|
export const exec = (param, element, state, context) => {
|
|
9
10
|
if (isFunction(param)) {
|
|
@@ -95,17 +96,18 @@ export const mergeArrayExclude = (arr, excl = []) => {
|
|
|
95
96
|
/**
|
|
96
97
|
* Deep cloning of object
|
|
97
98
|
*/
|
|
98
|
-
export const deepClone = (obj, excludeFrom = []) => {
|
|
99
|
+
export const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
|
|
99
100
|
const o = isArray(obj) ? [] : {}
|
|
100
101
|
for (const prop in obj) {
|
|
101
102
|
if (prop === '__proto__') continue
|
|
102
103
|
if (excludeFrom.includes(prop) || prop.startsWith('__')) continue
|
|
103
104
|
let objProp = obj[prop]
|
|
105
|
+
if (cleanUndefined && isUndefined(objProp)) continue
|
|
104
106
|
if (prop === 'extend' && isArray(objProp)) {
|
|
105
107
|
objProp = mergeArray(objProp)
|
|
106
108
|
}
|
|
107
109
|
if (isObjectLike(objProp)) {
|
|
108
|
-
o[prop] = deepClone(objProp, excludeFrom)
|
|
110
|
+
o[prop] = deepClone(objProp, excludeFrom, cleanUndefined)
|
|
109
111
|
} else o[prop] = objProp
|
|
110
112
|
}
|
|
111
113
|
return o
|
|
@@ -162,7 +164,7 @@ export const objectToString = (obj, indent = 0) => {
|
|
|
162
164
|
}
|
|
163
165
|
}
|
|
164
166
|
str += `${spaces} ]`
|
|
165
|
-
} else if (
|
|
167
|
+
} else if (isObjectLike(value)) {
|
|
166
168
|
str += objectToString(value, indent + 1)
|
|
167
169
|
} else if (isString(value)) {
|
|
168
170
|
str += stringIncludesAny(value, ['\n', '\'']) ? `\`${value}\`` : `'${value}'`
|
|
@@ -301,6 +303,8 @@ export const diff = (original, objToDiff, cache = {}) => {
|
|
|
301
303
|
return cache
|
|
302
304
|
}
|
|
303
305
|
|
|
306
|
+
export const deepDiff = deepObjectDiff
|
|
307
|
+
|
|
304
308
|
/**
|
|
305
309
|
* Overwrites object properties with another
|
|
306
310
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -23,8 +23,11 @@
|
|
|
23
23
|
"build": "yarn build:cjs",
|
|
24
24
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "bc6fd0276b416145cb0d1435a6ec12c97ea97753",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"deep-object-diff": "^1.1.9"
|
|
29
32
|
}
|
|
30
33
|
}
|