@domql/utils 2.5.18 → 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 +5 -3
- package/object.js +5 -4
- package/package.json +2 -2
package/dist/cjs/object.js
CHANGED
|
@@ -128,7 +128,7 @@ const deepCloneExclude = (obj, excludeFrom = []) => {
|
|
|
128
128
|
const mergeArrayExclude = (arr, excl = []) => {
|
|
129
129
|
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
130
130
|
};
|
|
131
|
-
const deepClone = (obj, excludeFrom = []) => {
|
|
131
|
+
const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
|
|
132
132
|
const o = (0, import_types.isArray)(obj) ? [] : {};
|
|
133
133
|
for (const prop in obj) {
|
|
134
134
|
if (prop === "__proto__")
|
|
@@ -136,11 +136,13 @@ const deepClone = (obj, excludeFrom = []) => {
|
|
|
136
136
|
if (excludeFrom.includes(prop) || prop.startsWith("__"))
|
|
137
137
|
continue;
|
|
138
138
|
let objProp = obj[prop];
|
|
139
|
+
if (cleanUndefined && (0, import_types.isUndefined)(objProp))
|
|
140
|
+
continue;
|
|
139
141
|
if (prop === "extend" && (0, import_types.isArray)(objProp)) {
|
|
140
142
|
objProp = (0, import_array.mergeArray)(objProp);
|
|
141
143
|
}
|
|
142
144
|
if ((0, import_types.isObjectLike)(objProp)) {
|
|
143
|
-
o[prop] = deepClone(objProp, excludeFrom);
|
|
145
|
+
o[prop] = deepClone(objProp, excludeFrom, cleanUndefined);
|
|
144
146
|
} else
|
|
145
147
|
o[prop] = objProp;
|
|
146
148
|
}
|
|
@@ -194,7 +196,7 @@ const objectToString = (obj, indent = 0) => {
|
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
198
|
str += `${spaces} ]`;
|
|
197
|
-
} else if ((0, import_types.
|
|
199
|
+
} else if ((0, import_types.isObjectLike)(value)) {
|
|
198
200
|
str += objectToString(value, indent + 1);
|
|
199
201
|
} else if ((0, import_types.isString)(value)) {
|
|
200
202
|
str += (0, import_string.stringIncludesAny)(value, ["\n", "'"]) ? `\`${value}\`` : `'${value}'`;
|
package/object.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
7
|
import { diff as deepObjectDiff } from 'deep-object-diff'
|
|
@@ -96,17 +96,18 @@ export const mergeArrayExclude = (arr, excl = []) => {
|
|
|
96
96
|
/**
|
|
97
97
|
* Deep cloning of object
|
|
98
98
|
*/
|
|
99
|
-
export const deepClone = (obj, excludeFrom = []) => {
|
|
99
|
+
export const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
|
|
100
100
|
const o = isArray(obj) ? [] : {}
|
|
101
101
|
for (const prop in obj) {
|
|
102
102
|
if (prop === '__proto__') continue
|
|
103
103
|
if (excludeFrom.includes(prop) || prop.startsWith('__')) continue
|
|
104
104
|
let objProp = obj[prop]
|
|
105
|
+
if (cleanUndefined && isUndefined(objProp)) continue
|
|
105
106
|
if (prop === 'extend' && isArray(objProp)) {
|
|
106
107
|
objProp = mergeArray(objProp)
|
|
107
108
|
}
|
|
108
109
|
if (isObjectLike(objProp)) {
|
|
109
|
-
o[prop] = deepClone(objProp, excludeFrom)
|
|
110
|
+
o[prop] = deepClone(objProp, excludeFrom, cleanUndefined)
|
|
110
111
|
} else o[prop] = objProp
|
|
111
112
|
}
|
|
112
113
|
return o
|
|
@@ -163,7 +164,7 @@ export const objectToString = (obj, indent = 0) => {
|
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
str += `${spaces} ]`
|
|
166
|
-
} else if (
|
|
167
|
+
} else if (isObjectLike(value)) {
|
|
167
168
|
str += objectToString(value, indent + 1)
|
|
168
169
|
} else if (isString(value)) {
|
|
169
170
|
str += stringIncludesAny(value, ['\n', '\'']) ? `\`${value}\`` : `'${value}'`
|
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,7 +23,7 @@
|
|
|
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
29
|
},
|