@domql/utils 2.2.0 → 2.3.0
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/node.js +1 -1
- package/object.js +31 -12
- package/package.json +2 -2
package/node.js
CHANGED
package/object.js
CHANGED
|
@@ -71,17 +71,17 @@ export const merge = (element, obj) => {
|
|
|
71
71
|
return element
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export const deepMerge = (element,
|
|
74
|
+
export const deepMerge = (element, extend) => {
|
|
75
75
|
// console.groupCollapsed('deepMerge:')
|
|
76
|
-
for (const e in
|
|
76
|
+
for (const e in extend) {
|
|
77
77
|
const elementProp = element[e]
|
|
78
|
-
const
|
|
78
|
+
const extendProp = extend[e]
|
|
79
79
|
// const cachedProps = cache.props
|
|
80
80
|
if (e === 'parent' || e === 'props') continue
|
|
81
81
|
if (elementProp === undefined) {
|
|
82
|
-
element[e] =
|
|
83
|
-
} else if (isObjectLike(elementProp) && isObject(
|
|
84
|
-
deepMerge(elementProp,
|
|
82
|
+
element[e] = extendProp
|
|
83
|
+
} else if (isObjectLike(elementProp) && isObject(extendProp)) {
|
|
84
|
+
deepMerge(elementProp, extendProp)
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
// console.groupEnd('deepMerge:')
|
|
@@ -105,7 +105,7 @@ export const deepClone = (obj, excluding = ['parent', 'node', '__element', '__ro
|
|
|
105
105
|
for (const prop in obj) {
|
|
106
106
|
if (excluding.indexOf(prop) > -1) continue
|
|
107
107
|
let objProp = obj[prop]
|
|
108
|
-
if (prop === '
|
|
108
|
+
if (prop === 'extend' && isArray(objProp)) {
|
|
109
109
|
objProp = mergeArray(objProp)
|
|
110
110
|
}
|
|
111
111
|
if (isObjectLike(objProp)) {
|
|
@@ -140,18 +140,37 @@ export const overwrite = (element, params, options) => {
|
|
|
140
140
|
export const diff = (obj, original, cache) => {
|
|
141
141
|
const changes = cache || {}
|
|
142
142
|
for (const e in obj) {
|
|
143
|
+
if (e === 'ref') continue
|
|
143
144
|
const originalProp = original[e]
|
|
144
145
|
const objProp = obj[e]
|
|
145
146
|
if (isObjectLike(originalProp) && isObjectLike(objProp)) {
|
|
146
147
|
changes[e] = {}
|
|
147
148
|
diff(originalProp, objProp, changes[e])
|
|
148
|
-
} else if (
|
|
149
|
+
} else if (objProp !== undefined) {
|
|
149
150
|
changes[e] = objProp
|
|
150
151
|
}
|
|
151
152
|
}
|
|
152
153
|
return changes
|
|
153
154
|
}
|
|
154
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Overwrites object properties with another
|
|
158
|
+
*/
|
|
159
|
+
export const overwriteObj = (params, obj) => {
|
|
160
|
+
const changes = {}
|
|
161
|
+
|
|
162
|
+
for (const e in params) {
|
|
163
|
+
const objProp = obj[e]
|
|
164
|
+
const paramsProp = params[e]
|
|
165
|
+
|
|
166
|
+
if (paramsProp) {
|
|
167
|
+
obj[e] = changes[e] = objProp
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return changes
|
|
172
|
+
}
|
|
173
|
+
|
|
155
174
|
/**
|
|
156
175
|
* Overwrites DEEPly object properties with another
|
|
157
176
|
*/
|
|
@@ -177,14 +196,14 @@ export const mergeIfExisted = (a, b) => {
|
|
|
177
196
|
}
|
|
178
197
|
|
|
179
198
|
/**
|
|
180
|
-
* Merges array
|
|
199
|
+
* Merges array extendtypes
|
|
181
200
|
*/
|
|
182
201
|
export const mergeArray = (arr) => {
|
|
183
202
|
return arr.reduce((a, c) => deepMerge(a, deepClone(c)), {})
|
|
184
203
|
}
|
|
185
204
|
|
|
186
205
|
/**
|
|
187
|
-
* Merges array
|
|
206
|
+
* Merges array extendtypes
|
|
188
207
|
*/
|
|
189
208
|
export const mergeAndCloneIfArray = obj => {
|
|
190
209
|
return isArray(obj) ? mergeArray(obj) : deepClone(obj)
|
|
@@ -197,8 +216,8 @@ export const flattenRecursive = (param, prop, stack = []) => {
|
|
|
197
216
|
const objectized = mergeAndCloneIfArray(param)
|
|
198
217
|
stack.push(objectized)
|
|
199
218
|
|
|
200
|
-
const
|
|
201
|
-
if (
|
|
219
|
+
const extendOfExtend = objectized[prop]
|
|
220
|
+
if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack)
|
|
202
221
|
|
|
203
222
|
delete objectized[prop]
|
|
204
223
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@domql/tags": "latest"
|
|
8
8
|
},
|
|
9
|
-
"gitHead": "
|
|
9
|
+
"gitHead": "02944ad228d2cf5f5727b08e9378d221b2f7205b",
|
|
10
10
|
"source": "index.js"
|
|
11
11
|
}
|