@domql/utils 2.5.200 → 3.0.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/array.js +26 -13
- package/cache.js +4 -0
- package/component.js +10 -227
- package/cookie.js +27 -24
- package/dist/cjs/array.js +27 -10
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/component.js +15 -206
- package/dist/cjs/cookie.js +14 -14
- package/dist/cjs/element.js +137 -0
- package/dist/cjs/events.js +37 -0
- package/dist/cjs/extends.js +351 -0
- package/dist/cjs/if.js +30 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/key.js +5 -0
- package/dist/cjs/keys.js +178 -0
- package/dist/cjs/methods.js +305 -0
- package/dist/cjs/object.js +78 -191
- package/dist/cjs/props.js +220 -0
- package/dist/cjs/scope.js +28 -0
- package/dist/cjs/state.js +175 -0
- package/dist/cjs/string.js +27 -15
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +27 -10
- package/dist/esm/cache.js +6 -0
- package/dist/esm/component.js +16 -225
- package/dist/esm/cookie.js +14 -14
- package/dist/esm/element.js +135 -0
- package/dist/esm/events.js +17 -0
- package/dist/esm/extends.js +349 -0
- package/dist/esm/if.js +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/key.js +5 -0
- package/dist/esm/keys.js +158 -0
- package/dist/esm/methods.js +285 -0
- package/dist/esm/object.js +79 -193
- package/dist/esm/props.js +216 -0
- package/dist/esm/scope.js +8 -0
- package/dist/esm/state.js +185 -0
- package/dist/esm/string.js +27 -15
- package/dist/esm/update.js +22 -0
- package/element.js +149 -0
- package/env.js +5 -2
- package/events.js +17 -0
- package/extends.js +425 -0
- package/if.js +14 -0
- package/index.js +10 -0
- package/key.js +6 -0
- package/keys.js +157 -0
- package/log.js +4 -1
- package/methods.js +315 -0
- package/node.js +21 -13
- package/object.js +122 -236
- package/package.json +3 -3
- package/props.js +249 -0
- package/scope.js +8 -0
- package/state.js +208 -0
- package/string.js +66 -30
- package/update.js +27 -0
package/object.js
CHANGED
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
isString,
|
|
10
10
|
is,
|
|
11
11
|
isUndefined,
|
|
12
|
-
isDate,
|
|
13
12
|
isNull
|
|
14
13
|
} from './types.js'
|
|
15
|
-
import {
|
|
14
|
+
import { unstackArrayOfObjects } from './array.js'
|
|
16
15
|
import { stringIncludesAny } from './string.js'
|
|
17
16
|
import { isDOMNode } from './node.js'
|
|
17
|
+
import { METHODS_EXL } from './keys.js'
|
|
18
18
|
|
|
19
19
|
const ENV = process.env.NODE_ENV
|
|
20
20
|
|
|
@@ -30,6 +30,18 @@ export const exec = (param, element, state, context) => {
|
|
|
30
30
|
return param
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
export const execPromise = async (param, element, state, context) => {
|
|
34
|
+
if (isFunction(param)) {
|
|
35
|
+
return await param.call(
|
|
36
|
+
element,
|
|
37
|
+
element,
|
|
38
|
+
state || element.state,
|
|
39
|
+
context || element.context
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
return param
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
export const map = (obj, extention, element) => {
|
|
34
46
|
for (const e in extention) {
|
|
35
47
|
obj[e] = exec(extention[e], element)
|
|
@@ -39,7 +51,9 @@ export const map = (obj, extention, element) => {
|
|
|
39
51
|
export const merge = (element, obj, excludeFrom = []) => {
|
|
40
52
|
for (const e in obj) {
|
|
41
53
|
const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, e)
|
|
42
|
-
if (!hasOwnProperty || excludeFrom.includes(e) || e.startsWith('__'))
|
|
54
|
+
if (!hasOwnProperty || excludeFrom.includes(e) || e.startsWith('__')) {
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
43
57
|
const elementProp = element[e]
|
|
44
58
|
const objProp = obj[e]
|
|
45
59
|
if (elementProp === undefined) {
|
|
@@ -49,10 +63,12 @@ export const merge = (element, obj, excludeFrom = []) => {
|
|
|
49
63
|
return element
|
|
50
64
|
}
|
|
51
65
|
|
|
52
|
-
export const deepMerge = (element, extend, excludeFrom =
|
|
66
|
+
export const deepMerge = (element, extend, excludeFrom = METHODS_EXL) => {
|
|
53
67
|
for (const e in extend) {
|
|
54
68
|
const hasOwnProperty = Object.prototype.hasOwnProperty.call(extend, e)
|
|
55
|
-
if (!hasOwnProperty || excludeFrom.includes(e) || e.startsWith('__'))
|
|
69
|
+
if (!hasOwnProperty || excludeFrom.includes(e) || e.startsWith('__')) {
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
56
72
|
const elementProp = element[e]
|
|
57
73
|
const extendProp = extend[e]
|
|
58
74
|
if (isObjectLike(elementProp) && isObjectLike(extendProp)) {
|
|
@@ -68,16 +84,18 @@ export const clone = (obj, excludeFrom = []) => {
|
|
|
68
84
|
const o = {}
|
|
69
85
|
for (const prop in obj) {
|
|
70
86
|
const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop)
|
|
71
|
-
if (
|
|
87
|
+
if (
|
|
88
|
+
!hasOwnProperty ||
|
|
89
|
+
excludeFrom.includes(prop) ||
|
|
90
|
+
prop.startsWith('__')
|
|
91
|
+
) {
|
|
92
|
+
continue
|
|
93
|
+
}
|
|
72
94
|
o[prop] = obj[prop]
|
|
73
95
|
}
|
|
74
96
|
return o
|
|
75
97
|
}
|
|
76
98
|
|
|
77
|
-
// Merge array, but exclude keys listed in 'excl'z
|
|
78
|
-
export const mergeArrayExclude = (arr, exclude = []) => {
|
|
79
|
-
return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {})
|
|
80
|
-
}
|
|
81
99
|
/**
|
|
82
100
|
* Enhanced deep clone function that combines features from multiple implementations
|
|
83
101
|
* @param {any} obj - Object to clone
|
|
@@ -87,7 +105,7 @@ export const mergeArrayExclude = (arr, exclude = []) => {
|
|
|
87
105
|
* @param {boolean} options.cleanNull - Remove null values
|
|
88
106
|
* @param {Window} options.window - Window object for cross-frame cloning
|
|
89
107
|
* @param {WeakMap} options.visited - WeakMap for tracking circular references
|
|
90
|
-
* @param {boolean} options.
|
|
108
|
+
* @param {boolean} options.handleExtends - Whether to handle 'extends' arrays specially
|
|
91
109
|
* @returns {any} Cloned object
|
|
92
110
|
*/
|
|
93
111
|
export const deepClone = (obj, options = {}) => {
|
|
@@ -97,7 +115,7 @@ export const deepClone = (obj, options = {}) => {
|
|
|
97
115
|
cleanNull = false,
|
|
98
116
|
window: targetWindow,
|
|
99
117
|
visited = new WeakMap(),
|
|
100
|
-
|
|
118
|
+
handleExtends = false
|
|
101
119
|
} = options
|
|
102
120
|
|
|
103
121
|
// Handle non-object types and special cases
|
|
@@ -116,8 +134,8 @@ export const deepClone = (obj, options = {}) => {
|
|
|
116
134
|
? new targetWindow.Array()
|
|
117
135
|
: new targetWindow.Object()
|
|
118
136
|
: isArray(obj)
|
|
119
|
-
|
|
120
|
-
|
|
137
|
+
? []
|
|
138
|
+
: {}
|
|
121
139
|
|
|
122
140
|
// Store the clone to handle circular references
|
|
123
141
|
visited.set(obj, clone)
|
|
@@ -127,12 +145,19 @@ export const deepClone = (obj, options = {}) => {
|
|
|
127
145
|
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue
|
|
128
146
|
|
|
129
147
|
// Skip excluded properties
|
|
130
|
-
if (exclude.includes(key) || key.startsWith('__') || key === '__proto__')
|
|
148
|
+
if (exclude.includes(key) || key.startsWith('__') || key === '__proto__') {
|
|
149
|
+
continue
|
|
150
|
+
}
|
|
131
151
|
|
|
132
152
|
const value = obj[key]
|
|
133
153
|
|
|
134
154
|
// Skip based on cleanup options
|
|
135
|
-
if (
|
|
155
|
+
if (
|
|
156
|
+
(cleanUndefined && isUndefined(value)) ||
|
|
157
|
+
(cleanNull && isNull(value))
|
|
158
|
+
) {
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
136
161
|
|
|
137
162
|
// Handle special cases
|
|
138
163
|
if (isDOMNode(value)) {
|
|
@@ -140,9 +165,9 @@ export const deepClone = (obj, options = {}) => {
|
|
|
140
165
|
continue
|
|
141
166
|
}
|
|
142
167
|
|
|
143
|
-
// Handle '
|
|
144
|
-
if (
|
|
145
|
-
clone[key] =
|
|
168
|
+
// Handle 'extends' array if enabled
|
|
169
|
+
if (handleExtends && key === 'extends' && isArray(value)) {
|
|
170
|
+
clone[key] = unstackArrayOfObjects(value, exclude)
|
|
146
171
|
continue
|
|
147
172
|
}
|
|
148
173
|
|
|
@@ -171,7 +196,10 @@ export const deepClone = (obj, options = {}) => {
|
|
|
171
196
|
*/
|
|
172
197
|
export const deepStringify = (obj, stringified = {}) => {
|
|
173
198
|
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
|
|
174
|
-
(obj.__element || obj.parent?.__element).warn(
|
|
199
|
+
;(obj.__element || obj.parent?.__element).warn(
|
|
200
|
+
'Trying to clone element or state at',
|
|
201
|
+
obj
|
|
202
|
+
)
|
|
175
203
|
obj = obj.parse?.()
|
|
176
204
|
}
|
|
177
205
|
|
|
@@ -201,42 +229,6 @@ export const deepStringify = (obj, stringified = {}) => {
|
|
|
201
229
|
return stringified
|
|
202
230
|
}
|
|
203
231
|
|
|
204
|
-
const MAX_DEPTH = 100 // Adjust this value as needed
|
|
205
|
-
export const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = '') => {
|
|
206
|
-
if (depth > MAX_DEPTH) {
|
|
207
|
-
console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`)
|
|
208
|
-
return '[MAX_DEPTH_EXCEEDED]'
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
for (const prop in obj) {
|
|
212
|
-
const currentPath = path ? `${path}.${prop}` : prop
|
|
213
|
-
const objProp = obj[prop]
|
|
214
|
-
|
|
215
|
-
if (isFunction(objProp)) {
|
|
216
|
-
stringified[prop] = objProp.toString()
|
|
217
|
-
} else if (isObject(objProp)) {
|
|
218
|
-
stringified[prop] = {}
|
|
219
|
-
deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath)
|
|
220
|
-
} else if (isArray(objProp)) {
|
|
221
|
-
stringified[prop] = []
|
|
222
|
-
objProp.forEach((v, i) => {
|
|
223
|
-
const itemPath = `${currentPath}[${i}]`
|
|
224
|
-
if (isObject(v)) {
|
|
225
|
-
stringified[prop][i] = {}
|
|
226
|
-
deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath)
|
|
227
|
-
} else if (isFunction(v)) {
|
|
228
|
-
stringified[prop][i] = v.toString()
|
|
229
|
-
} else {
|
|
230
|
-
stringified[prop][i] = v
|
|
231
|
-
}
|
|
232
|
-
})
|
|
233
|
-
} else {
|
|
234
|
-
stringified[prop] = objProp
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return stringified
|
|
238
|
-
}
|
|
239
|
-
|
|
240
232
|
export const objectToString = (obj = {}, indent = 0) => {
|
|
241
233
|
// Handle empty object case
|
|
242
234
|
if (obj === null || typeof obj !== 'object') {
|
|
@@ -252,7 +244,22 @@ export const objectToString = (obj = {}, indent = 0) => {
|
|
|
252
244
|
let str = '{\n'
|
|
253
245
|
|
|
254
246
|
for (const [key, value] of Object.entries(obj)) {
|
|
255
|
-
const keyNotAllowdChars = stringIncludesAny(key, [
|
|
247
|
+
const keyNotAllowdChars = stringIncludesAny(key, [
|
|
248
|
+
'&',
|
|
249
|
+
'*',
|
|
250
|
+
'-',
|
|
251
|
+
':',
|
|
252
|
+
'%',
|
|
253
|
+
'{',
|
|
254
|
+
'}',
|
|
255
|
+
'>',
|
|
256
|
+
'<',
|
|
257
|
+
'@',
|
|
258
|
+
'.',
|
|
259
|
+
'/',
|
|
260
|
+
'!',
|
|
261
|
+
' '
|
|
262
|
+
])
|
|
256
263
|
const stringedKey = keyNotAllowdChars ? `'${key}'` : key
|
|
257
264
|
str += `${spaces} ${stringedKey}: `
|
|
258
265
|
|
|
@@ -271,7 +278,9 @@ export const objectToString = (obj = {}, indent = 0) => {
|
|
|
271
278
|
} else if (isObjectLike(value)) {
|
|
272
279
|
str += objectToString(value, indent + 1)
|
|
273
280
|
} else if (isString(value)) {
|
|
274
|
-
str += stringIncludesAny(value, ['\n', '
|
|
281
|
+
str += stringIncludesAny(value, ['\n', "'"])
|
|
282
|
+
? `\`${value}\``
|
|
283
|
+
: `'${value}'`
|
|
275
284
|
} else {
|
|
276
285
|
str += value
|
|
277
286
|
}
|
|
@@ -283,35 +292,7 @@ export const objectToString = (obj = {}, indent = 0) => {
|
|
|
283
292
|
return str
|
|
284
293
|
}
|
|
285
294
|
|
|
286
|
-
|
|
287
|
-
* Stringify object
|
|
288
|
-
*/
|
|
289
|
-
export const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
290
|
-
for (const prop in obj) {
|
|
291
|
-
const objProp = obj[prop]
|
|
292
|
-
if (isFunction(objProp)) continue
|
|
293
|
-
else if (isObject(objProp)) {
|
|
294
|
-
detached[prop] = {}
|
|
295
|
-
deepStringify(objProp, detached[prop])
|
|
296
|
-
} else if (isArray(objProp)) {
|
|
297
|
-
detached[prop] = []
|
|
298
|
-
objProp.forEach((v, i) => {
|
|
299
|
-
if (isFunction(v)) return
|
|
300
|
-
if (isObject(v)) {
|
|
301
|
-
detached[prop][i] = {}
|
|
302
|
-
detachFunctionsFromObject(v, detached[prop][i])
|
|
303
|
-
} else {
|
|
304
|
-
detached[prop][i] = v
|
|
305
|
-
}
|
|
306
|
-
})
|
|
307
|
-
} else {
|
|
308
|
-
detached[prop] = objProp
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return detached
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
export const hasFunction = (str) => {
|
|
295
|
+
export const hasFunction = str => {
|
|
315
296
|
if (!str) return false
|
|
316
297
|
|
|
317
298
|
const trimmed = str.trim().replace(/\n\s*/g, ' ').trim()
|
|
@@ -357,7 +338,7 @@ export const deepDestringify = (obj, destringified = {}) => {
|
|
|
357
338
|
}
|
|
358
339
|
} else if (isArray(objProp)) {
|
|
359
340
|
destringified[prop] = []
|
|
360
|
-
objProp.forEach(
|
|
341
|
+
objProp.forEach(arrProp => {
|
|
361
342
|
if (isString(arrProp)) {
|
|
362
343
|
if (hasFunction(arrProp)) {
|
|
363
344
|
try {
|
|
@@ -387,123 +368,34 @@ export const deepDestringify = (obj, destringified = {}) => {
|
|
|
387
368
|
export const stringToObject = (str, opts = { verbose: true }) => {
|
|
388
369
|
try {
|
|
389
370
|
return str ? window.eval('(' + str + ')') : {} // eslint-disable-line
|
|
390
|
-
} catch (e) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
export const diffObjects = (original, objToDiff, cache) => {
|
|
394
|
-
for (const e in objToDiff) {
|
|
395
|
-
if (e === 'ref') continue
|
|
396
|
-
|
|
397
|
-
const originalProp = original[e]
|
|
398
|
-
const objToDiffProp = objToDiff[e]
|
|
399
|
-
|
|
400
|
-
if (isObject(originalProp) && isObject(objToDiffProp)) {
|
|
401
|
-
cache[e] = {}
|
|
402
|
-
diff(originalProp, objToDiffProp, cache[e])
|
|
403
|
-
} else if (objToDiffProp !== undefined) {
|
|
404
|
-
cache[e] = objToDiffProp
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
return cache
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
export const diffArrays = (original, objToDiff, cache) => {
|
|
411
|
-
if (original.length !== objToDiff.length) {
|
|
412
|
-
cache = objToDiff
|
|
413
|
-
} else {
|
|
414
|
-
const diffArr = []
|
|
415
|
-
for (let i = 0; i < original.length; i++) {
|
|
416
|
-
const diffObj = diff(original[i], objToDiff[i])
|
|
417
|
-
if (Object.keys(diffObj).length > 0) {
|
|
418
|
-
diffArr.push(diffObj)
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
if (diffArr.length > 0) {
|
|
422
|
-
cache = diffArr
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
return cache
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
export const diff = (original, objToDiff, cache = {}) => {
|
|
429
|
-
if (isArray(original) && isArray(objToDiff)) {
|
|
430
|
-
cache = []
|
|
431
|
-
diffArrays(original, objToDiff, cache)
|
|
432
|
-
} else {
|
|
433
|
-
diffObjects(original, objToDiff, cache)
|
|
371
|
+
} catch (e) {
|
|
372
|
+
if (opts.verbose) console.warn(e)
|
|
434
373
|
}
|
|
435
|
-
|
|
436
|
-
return cache
|
|
437
374
|
}
|
|
438
375
|
|
|
439
|
-
export const hasOwnProperty = (o, ...args) =>
|
|
376
|
+
export const hasOwnProperty = (o, ...args) =>
|
|
377
|
+
Object.prototype.hasOwnProperty.call(o, ...args)
|
|
440
378
|
|
|
441
379
|
export const isEmpty = o => Object.keys(o).length === 0
|
|
442
380
|
|
|
443
|
-
export const isEmptyObject =
|
|
381
|
+
export const isEmptyObject = o => isObject(o) && isEmpty(o)
|
|
444
382
|
|
|
445
383
|
export const makeObjectWithoutPrototype = () => Object.create(null)
|
|
446
384
|
|
|
447
|
-
// by mattphillips
|
|
448
|
-
// https://github.com/mattphillips/deep-object-diff/blob/main/src/diff.js
|
|
449
|
-
export const deepDiff = (lhs, rhs) => {
|
|
450
|
-
if (lhs === rhs) return {}
|
|
451
|
-
|
|
452
|
-
if (!isObjectLike(lhs) || !isObjectLike(rhs)) return rhs
|
|
453
|
-
|
|
454
|
-
const deletedValues = Object.keys(lhs).reduce((acc, key) => {
|
|
455
|
-
if (!hasOwnProperty(rhs, key)) {
|
|
456
|
-
acc[key] = undefined
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
return acc
|
|
460
|
-
}, makeObjectWithoutPrototype())
|
|
461
|
-
|
|
462
|
-
if (isDate(lhs) || isDate(rhs)) {
|
|
463
|
-
if (lhs.valueOf() === rhs.valueOf()) return {}
|
|
464
|
-
return rhs
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
return Object.keys(rhs).reduce((acc, key) => {
|
|
468
|
-
if (!hasOwnProperty(lhs, key)) {
|
|
469
|
-
acc[key] = rhs[key]
|
|
470
|
-
return acc
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const difference = diff(lhs[key], rhs[key])
|
|
474
|
-
|
|
475
|
-
if (isEmptyObject(difference) && !isDate(difference) && (isEmptyObject(lhs[key]) || !isEmptyObject(rhs[key]))) {
|
|
476
|
-
return acc
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
acc[key] = difference
|
|
480
|
-
return acc
|
|
481
|
-
}, deletedValues)
|
|
482
|
-
}
|
|
483
|
-
|
|
484
385
|
/**
|
|
485
386
|
* Overwrites object properties with another
|
|
486
387
|
*/
|
|
487
388
|
export const overwrite = (element, params, opts = {}) => {
|
|
488
|
-
const { __ref: ref } = element
|
|
489
389
|
const excl = opts.exclude || []
|
|
490
390
|
const allowUnderscore = opts.preventUnderscore
|
|
491
|
-
const preventCaching = opts.preventCaching
|
|
492
391
|
|
|
493
392
|
for (const e in params) {
|
|
494
393
|
if (excl.includes(e) || (!allowUnderscore && e.startsWith('__'))) continue
|
|
495
394
|
|
|
496
|
-
const elementProp = element[e]
|
|
497
395
|
const paramsProp = params[e]
|
|
498
396
|
|
|
499
397
|
if (paramsProp !== undefined) {
|
|
500
398
|
element[e] = paramsProp
|
|
501
|
-
if (ref && !preventCaching) {
|
|
502
|
-
ref.__cache[e] = elementProp
|
|
503
|
-
}
|
|
504
|
-
if (isObject(opts.diff)) {
|
|
505
|
-
diff[e] = elementProp
|
|
506
|
-
}
|
|
507
399
|
}
|
|
508
400
|
}
|
|
509
401
|
|
|
@@ -521,11 +413,21 @@ export const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
|
521
413
|
/**
|
|
522
414
|
* Overwrites DEEPLY object properties with another
|
|
523
415
|
*/
|
|
524
|
-
export const overwriteDeep = (
|
|
416
|
+
export const overwriteDeep = (
|
|
417
|
+
obj,
|
|
418
|
+
params,
|
|
419
|
+
opts = {},
|
|
420
|
+
visited = new WeakMap()
|
|
421
|
+
) => {
|
|
525
422
|
const excl = opts.exclude || []
|
|
526
423
|
const forcedExclude = opts.preventForce ? [] : ['node', 'window']
|
|
527
424
|
|
|
528
|
-
if (
|
|
425
|
+
if (
|
|
426
|
+
!isObjectLike(obj) ||
|
|
427
|
+
!isObjectLike(params) ||
|
|
428
|
+
isDOMNode(obj) ||
|
|
429
|
+
isDOMNode(params)
|
|
430
|
+
) {
|
|
529
431
|
return params
|
|
530
432
|
}
|
|
531
433
|
|
|
@@ -551,29 +453,6 @@ export const overwriteDeep = (obj, params, opts = {}, visited = new WeakMap()) =
|
|
|
551
453
|
return obj
|
|
552
454
|
}
|
|
553
455
|
|
|
554
|
-
/**
|
|
555
|
-
* Overwrites object properties with another
|
|
556
|
-
*/
|
|
557
|
-
export const mergeIfExisted = (a, b) => {
|
|
558
|
-
if (isObjectLike(a) && isObjectLike(b)) return deepMerge(a, b)
|
|
559
|
-
return a || b
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* Overwrites object properties with another
|
|
564
|
-
*/
|
|
565
|
-
export const flattenRecursive = (param, prop, stack = []) => {
|
|
566
|
-
const objectized = mergeAndCloneIfArray(param)
|
|
567
|
-
stack.push(objectized)
|
|
568
|
-
|
|
569
|
-
const extendOfExtend = objectized[prop]
|
|
570
|
-
if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack)
|
|
571
|
-
|
|
572
|
-
delete objectized[prop]
|
|
573
|
-
|
|
574
|
-
return stack
|
|
575
|
-
}
|
|
576
|
-
|
|
577
456
|
/**
|
|
578
457
|
* Recursively compares two values to determine if they are deeply equal.
|
|
579
458
|
*
|
|
@@ -610,7 +489,12 @@ export const flattenRecursive = (param, prop, stack = []) => {
|
|
|
610
489
|
*/
|
|
611
490
|
export const isEqualDeep = (param, element, visited = new Set()) => {
|
|
612
491
|
// Check if both values are non-null objects
|
|
613
|
-
if (
|
|
492
|
+
if (
|
|
493
|
+
typeof param !== 'object' ||
|
|
494
|
+
typeof element !== 'object' ||
|
|
495
|
+
param === null ||
|
|
496
|
+
element === null
|
|
497
|
+
) {
|
|
614
498
|
return param === element // Compare non-object values directly
|
|
615
499
|
}
|
|
616
500
|
|
|
@@ -650,42 +534,39 @@ export const isEqualDeep = (param, element, visited = new Set()) => {
|
|
|
650
534
|
|
|
651
535
|
export const deepContains = (obj1, obj2, ignoredKeys = ['node', '__ref']) => {
|
|
652
536
|
if (obj1 === obj2) return true
|
|
653
|
-
if (!isObjectLike(obj1) || !isObjectLike(obj2)) return
|
|
537
|
+
if (!isObjectLike(obj1) || !isObjectLike(obj2)) return obj1 === obj2
|
|
654
538
|
if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2
|
|
655
539
|
|
|
656
|
-
const stack = [[obj1, obj2]]
|
|
657
540
|
const visited = new WeakSet()
|
|
658
541
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
if (visited.has(current1)) continue
|
|
663
|
-
visited.add(current1)
|
|
542
|
+
function checkContains (target, source) {
|
|
543
|
+
if (visited.has(source)) return true
|
|
544
|
+
visited.add(source)
|
|
664
545
|
|
|
665
|
-
|
|
666
|
-
const
|
|
546
|
+
// Check each property in source
|
|
547
|
+
for (const key in source) {
|
|
548
|
+
if (!Object.prototype.hasOwnProperty.call(source, key)) continue
|
|
549
|
+
if (ignoredKeys.includes(key)) continue
|
|
667
550
|
|
|
668
|
-
|
|
551
|
+
// If key doesn't exist in target, return false
|
|
552
|
+
if (!Object.prototype.hasOwnProperty.call(target, key)) return false
|
|
669
553
|
|
|
670
|
-
|
|
671
|
-
|
|
554
|
+
const sourceValue = source[key]
|
|
555
|
+
const targetValue = target[key]
|
|
672
556
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
} else if (isObjectLike(value1) && isObjectLike(value2)) {
|
|
679
|
-
if (value1 !== value2) {
|
|
680
|
-
stack.push([value1, value2])
|
|
681
|
-
}
|
|
682
|
-
} else if (value1 !== value2) {
|
|
557
|
+
if (isDOMNode(sourceValue) || isDOMNode(targetValue)) {
|
|
558
|
+
if (sourceValue !== targetValue) return false
|
|
559
|
+
} else if (isObjectLike(sourceValue) && isObjectLike(targetValue)) {
|
|
560
|
+
if (!checkContains(targetValue, sourceValue)) return false
|
|
561
|
+
} else if (sourceValue !== targetValue) {
|
|
683
562
|
return false
|
|
684
563
|
}
|
|
685
564
|
}
|
|
565
|
+
|
|
566
|
+
return true
|
|
686
567
|
}
|
|
687
568
|
|
|
688
|
-
return
|
|
569
|
+
return checkContains(obj1, obj2)
|
|
689
570
|
}
|
|
690
571
|
|
|
691
572
|
export const removeFromObject = (obj, props) => {
|
|
@@ -695,12 +576,14 @@ export const removeFromObject = (obj, props) => {
|
|
|
695
576
|
} else if (isArray(props)) {
|
|
696
577
|
props.forEach(prop => delete obj[prop])
|
|
697
578
|
} else {
|
|
698
|
-
throw new Error(
|
|
579
|
+
throw new Error(
|
|
580
|
+
'Invalid input: props must be a string or an array of strings'
|
|
581
|
+
)
|
|
699
582
|
}
|
|
700
583
|
return obj
|
|
701
584
|
}
|
|
702
585
|
|
|
703
|
-
export const createObjectWithoutPrototype =
|
|
586
|
+
export const createObjectWithoutPrototype = obj => {
|
|
704
587
|
if (obj === null || typeof obj !== 'object') {
|
|
705
588
|
return obj // Return the value if obj is not an object
|
|
706
589
|
}
|
|
@@ -727,7 +610,7 @@ export const createNestedObject = (arr, lastValue) => {
|
|
|
727
610
|
if (!obj[value]) {
|
|
728
611
|
obj[value] = {}
|
|
729
612
|
}
|
|
730
|
-
if (index === arr.length - 1 && lastValue
|
|
613
|
+
if (index === arr.length - 1 && lastValue) {
|
|
731
614
|
obj[value] = lastValue
|
|
732
615
|
}
|
|
733
616
|
return obj[value]
|
|
@@ -816,7 +699,10 @@ export const detectInfiniteLoop = arr => {
|
|
|
816
699
|
// If the pattern repeats more than `maxRepeats`, throw a warning
|
|
817
700
|
if (repeatCount >= maxRepeats * 2) {
|
|
818
701
|
if (ENV === 'test' || ENV === 'development') {
|
|
819
|
-
console.warn(
|
|
702
|
+
console.warn(
|
|
703
|
+
'Warning: Potential infinite loop detected due to repeated sequence:',
|
|
704
|
+
pattern
|
|
705
|
+
)
|
|
820
706
|
}
|
|
821
707
|
return true
|
|
822
708
|
}
|
|
@@ -824,7 +710,7 @@ export const detectInfiniteLoop = arr => {
|
|
|
824
710
|
}
|
|
825
711
|
}
|
|
826
712
|
|
|
827
|
-
export const isCyclic =
|
|
713
|
+
export const isCyclic = obj => {
|
|
828
714
|
const seenObjects = []
|
|
829
715
|
|
|
830
716
|
function detect (obj) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"default": "./
|
|
10
|
+
"default": "./index.js",
|
|
11
11
|
"import": "./dist/esm/index.js",
|
|
12
12
|
"require": "./dist/cjs/index.js"
|
|
13
13
|
}
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"build": "rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
25
25
|
"prepublish": "npm run build; npm run copy:package:cjs"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "bcbdc271a602b958de6a60ab387ea7715a935dc1",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@babel/core": "^7.12.0"
|
|
30
30
|
}
|