@domql/utils 2.31.26 → 2.31.27

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.
@@ -23,15 +23,16 @@ __export(object_exports, {
23
23
  createObjectWithoutPrototype: () => createObjectWithoutPrototype,
24
24
  deepClone: () => deepClone,
25
25
  deepContains: () => deepContains,
26
- deepDestringify: () => deepDestringify,
26
+ deepDestringifyFunctions: () => deepDestringifyFunctions,
27
27
  deepDiff: () => deepDiff,
28
28
  deepMerge: () => deepMerge,
29
- deepStringify: () => deepStringify,
30
- deepStringifyWithMaxDepth: () => deepStringifyWithMaxDepth,
29
+ deepStringifyFunctions: () => deepStringifyFunctions,
30
+ deepStringifyFunctionsWithMaxDepth: () => deepStringifyFunctionsWithMaxDepth,
31
31
  detachFunctionsFromObject: () => detachFunctionsFromObject,
32
32
  detectInfiniteLoop: () => detectInfiniteLoop,
33
33
  diff: () => diff,
34
34
  diffObjects: () => diffObjects,
35
+ evalStringToObject: () => evalStringToObject,
35
36
  excludeKeysFromObject: () => excludeKeysFromObject,
36
37
  exec: () => exec,
37
38
  flattenRecursive: () => flattenRecursive,
@@ -53,8 +54,7 @@ __export(object_exports, {
53
54
  overwriteShallow: () => overwriteShallow,
54
55
  removeFromObject: () => removeFromObject,
55
56
  removeNestedKeyByPath: () => removeNestedKeyByPath,
56
- setInObjectByPath: () => setInObjectByPath,
57
- stringToObject: () => stringToObject
57
+ setInObjectByPath: () => setInObjectByPath
58
58
  });
59
59
  module.exports = __toCommonJS(object_exports);
60
60
  var import_globals = require("./globals.js");
@@ -182,7 +182,7 @@ const deepClone = (obj, options = {}) => {
182
182
  }
183
183
  return clone2;
184
184
  };
185
- const deepStringify = (obj, stringified = {}) => {
185
+ const deepStringifyFunctions = (obj, stringified = {}) => {
186
186
  var _a, _b;
187
187
  if (!obj) return;
188
188
  if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
@@ -199,13 +199,13 @@ const deepStringify = (obj, stringified = {}) => {
199
199
  stringified[prop] = objProp.toString();
200
200
  } else if ((0, import_types.isObject)(objProp)) {
201
201
  stringified[prop] = {};
202
- deepStringify(objProp, stringified[prop]);
202
+ deepStringifyFunctions(objProp, stringified[prop]);
203
203
  } else if ((0, import_types.isArray)(objProp)) {
204
204
  stringified[prop] = [];
205
205
  objProp.forEach((v, i) => {
206
206
  if ((0, import_types.isObject)(v)) {
207
207
  stringified[prop][i] = {};
208
- deepStringify(v, stringified[prop][i]);
208
+ deepStringifyFunctions(v, stringified[prop][i]);
209
209
  } else if ((0, import_types.isFunction)(v)) {
210
210
  stringified[prop][i] = v.toString();
211
211
  } else {
@@ -219,7 +219,7 @@ const deepStringify = (obj, stringified = {}) => {
219
219
  return stringified;
220
220
  };
221
221
  const MAX_DEPTH = 100;
222
- const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
222
+ const deepStringifyFunctionsWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
223
223
  if (depth > MAX_DEPTH) {
224
224
  console.warn(
225
225
  `Maximum depth exceeded at path: ${path}. Possible circular reference.`
@@ -233,7 +233,7 @@ const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "")
233
233
  stringified[prop] = objProp.toString();
234
234
  } else if ((0, import_types.isObject)(objProp)) {
235
235
  stringified[prop] = {};
236
- deepStringifyWithMaxDepth(
236
+ deepStringifyFunctionsWithMaxDepth(
237
237
  objProp,
238
238
  stringified[prop],
239
239
  depth + 1,
@@ -245,7 +245,7 @@ const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "")
245
245
  const itemPath = `${currentPath}[${i}]`;
246
246
  if ((0, import_types.isObject)(v)) {
247
247
  stringified[prop][i] = {};
248
- deepStringifyWithMaxDepth(
248
+ deepStringifyFunctionsWithMaxDepth(
249
249
  v,
250
250
  stringified[prop][i],
251
251
  depth + 1,
@@ -342,7 +342,7 @@ const detachFunctionsFromObject = (obj, detached = {}) => {
342
342
  if ((0, import_types.isFunction)(objProp)) continue;
343
343
  else if ((0, import_types.isObject)(objProp)) {
344
344
  detached[prop] = {};
345
- deepStringify(objProp, detached[prop]);
345
+ deepStringifyFunctions(objProp, detached[prop]);
346
346
  } else if ((0, import_types.isArray)(objProp)) {
347
347
  detached[prop] = [];
348
348
  objProp.forEach((v, i) => {
@@ -381,7 +381,7 @@ const hasFunction = (str) => {
381
381
  const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes("=>");
382
382
  return (isFunction2 || isClass) && !isObjectLiteral && !isArrayLiteral && !isJSONLike;
383
383
  };
384
- const deepDestringify = (obj, destringified = {}) => {
384
+ const deepDestringifyFunctions = (obj, destringified = {}) => {
385
385
  for (const prop in obj) {
386
386
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
387
387
  if (!hasOwnProperty2) continue;
@@ -412,30 +412,40 @@ const deepDestringify = (obj, destringified = {}) => {
412
412
  destringified[prop].push(arrProp);
413
413
  }
414
414
  } else if ((0, import_types.isObject)(arrProp)) {
415
- destringified[prop].push(deepDestringify(arrProp));
415
+ destringified[prop].push(deepDestringifyFunctions(arrProp));
416
416
  } else {
417
417
  destringified[prop].push(arrProp);
418
418
  }
419
419
  });
420
420
  } else if ((0, import_types.isObject)(objProp)) {
421
- destringified[prop] = deepDestringify(objProp, destringified[prop]);
421
+ destringified[prop] = deepDestringifyFunctions(
422
+ objProp,
423
+ destringified[prop]
424
+ );
422
425
  } else {
423
426
  destringified[prop] = objProp;
424
427
  }
425
428
  }
426
429
  return destringified;
427
430
  };
428
- const stringToObject = (str, opts = { verbose: true }) => {
431
+ const evalStringToObject = (str, opts = { verbose: true }) => {
429
432
  try {
430
- return str ? import_globals.window.eval("(" + str + ")") : {};
433
+ return str ? (opts.window || import_globals.window).eval("(" + str + ")") : {};
431
434
  } catch (e) {
432
435
  if (opts.verbose) console.warn(e);
433
- if (opts.errorCallback) return opts.errorCallback(e);
436
+ if (opts.onError) return opts.onError(e);
434
437
  }
435
438
  };
436
439
  const diffObjects = (original, objToDiff, cache, opts) => {
437
440
  let hasDiff = false;
438
- const allKeys = /* @__PURE__ */ new Set([...Object.keys(original), ...Object.keys(objToDiff)]);
441
+ const originalKeys = Object.keys(original);
442
+ const diffKeys = Object.keys(objToDiff);
443
+ const allKeys = [.../* @__PURE__ */ new Set([...originalKeys, ...diffKeys])];
444
+ const originalKeyOrder = originalKeys.join(",");
445
+ const diffKeyOrder = diffKeys.filter((k) => originalKeys.includes(k)).join(",");
446
+ if (originalKeyOrder !== diffKeyOrder) {
447
+ hasDiff = true;
448
+ }
439
449
  for (const key of allKeys) {
440
450
  if (key === "ref") continue;
441
451
  const originalProp = original[key];
@@ -469,6 +479,11 @@ const diffArrays = (original, objToDiff, cache, opts) => {
469
479
  return objToDiff;
470
480
  }
471
481
  let hasDiff = false;
482
+ const originalStringified = original.map((item) => JSON.stringify(item));
483
+ const diffStringified = objToDiff.map((item) => JSON.stringify(item));
484
+ if (originalStringified.join(",") !== diffStringified.join(",")) {
485
+ hasDiff = true;
486
+ }
472
487
  for (let i = 0; i < original.length; i++) {
473
488
  const diffObj = diff(original[i], objToDiff[i], {}, opts);
474
489
  if (diffObj && ((0, import_types.isObject)(diffObj) ? Object.keys(diffObj).length > 0 : true)) {
@@ -476,15 +491,15 @@ const diffArrays = (original, objToDiff, cache, opts) => {
476
491
  hasDiff = true;
477
492
  }
478
493
  }
479
- return hasDiff ? cache : void 0;
494
+ return hasDiff ? objToDiff : void 0;
480
495
  };
481
496
  const diff = (original, objToDiff, cache = {}, opts = {}) => {
482
497
  if (opts.cloneInstances) {
483
498
  original = deepClone(original);
484
499
  objToDiff = deepClone(objToDiff);
485
500
  }
486
- original = deepStringify(original);
487
- objToDiff = deepStringify(objToDiff);
501
+ original = deepStringifyFunctions(original);
502
+ objToDiff = deepStringifyFunctions(objToDiff);
488
503
  if ((0, import_types.isArray)(original) && (0, import_types.isArray)(objToDiff)) {
489
504
  const result = diffArrays(original, objToDiff, [], opts);
490
505
  return result === void 0 ? {} : result;
@@ -151,7 +151,7 @@ const deepClone = (obj, options = {}) => {
151
151
  }
152
152
  return clone2;
153
153
  };
154
- const deepStringify = (obj, stringified = {}) => {
154
+ const deepStringifyFunctions = (obj, stringified = {}) => {
155
155
  var _a, _b;
156
156
  if (!obj) return;
157
157
  if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
@@ -168,13 +168,13 @@ const deepStringify = (obj, stringified = {}) => {
168
168
  stringified[prop] = objProp.toString();
169
169
  } else if (isObject(objProp)) {
170
170
  stringified[prop] = {};
171
- deepStringify(objProp, stringified[prop]);
171
+ deepStringifyFunctions(objProp, stringified[prop]);
172
172
  } else if (isArray(objProp)) {
173
173
  stringified[prop] = [];
174
174
  objProp.forEach((v, i) => {
175
175
  if (isObject(v)) {
176
176
  stringified[prop][i] = {};
177
- deepStringify(v, stringified[prop][i]);
177
+ deepStringifyFunctions(v, stringified[prop][i]);
178
178
  } else if (isFunction(v)) {
179
179
  stringified[prop][i] = v.toString();
180
180
  } else {
@@ -188,7 +188,7 @@ const deepStringify = (obj, stringified = {}) => {
188
188
  return stringified;
189
189
  };
190
190
  const MAX_DEPTH = 100;
191
- const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
191
+ const deepStringifyFunctionsWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
192
192
  if (depth > MAX_DEPTH) {
193
193
  console.warn(
194
194
  `Maximum depth exceeded at path: ${path}. Possible circular reference.`
@@ -202,7 +202,7 @@ const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "")
202
202
  stringified[prop] = objProp.toString();
203
203
  } else if (isObject(objProp)) {
204
204
  stringified[prop] = {};
205
- deepStringifyWithMaxDepth(
205
+ deepStringifyFunctionsWithMaxDepth(
206
206
  objProp,
207
207
  stringified[prop],
208
208
  depth + 1,
@@ -214,7 +214,7 @@ const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "")
214
214
  const itemPath = `${currentPath}[${i}]`;
215
215
  if (isObject(v)) {
216
216
  stringified[prop][i] = {};
217
- deepStringifyWithMaxDepth(
217
+ deepStringifyFunctionsWithMaxDepth(
218
218
  v,
219
219
  stringified[prop][i],
220
220
  depth + 1,
@@ -311,7 +311,7 @@ const detachFunctionsFromObject = (obj, detached = {}) => {
311
311
  if (isFunction(objProp)) continue;
312
312
  else if (isObject(objProp)) {
313
313
  detached[prop] = {};
314
- deepStringify(objProp, detached[prop]);
314
+ deepStringifyFunctions(objProp, detached[prop]);
315
315
  } else if (isArray(objProp)) {
316
316
  detached[prop] = [];
317
317
  objProp.forEach((v, i) => {
@@ -350,7 +350,7 @@ const hasFunction = (str) => {
350
350
  const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes("=>");
351
351
  return (isFunction2 || isClass) && !isObjectLiteral && !isArrayLiteral && !isJSONLike;
352
352
  };
353
- const deepDestringify = (obj, destringified = {}) => {
353
+ const deepDestringifyFunctions = (obj, destringified = {}) => {
354
354
  for (const prop in obj) {
355
355
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
356
356
  if (!hasOwnProperty2) continue;
@@ -381,30 +381,40 @@ const deepDestringify = (obj, destringified = {}) => {
381
381
  destringified[prop].push(arrProp);
382
382
  }
383
383
  } else if (isObject(arrProp)) {
384
- destringified[prop].push(deepDestringify(arrProp));
384
+ destringified[prop].push(deepDestringifyFunctions(arrProp));
385
385
  } else {
386
386
  destringified[prop].push(arrProp);
387
387
  }
388
388
  });
389
389
  } else if (isObject(objProp)) {
390
- destringified[prop] = deepDestringify(objProp, destringified[prop]);
390
+ destringified[prop] = deepDestringifyFunctions(
391
+ objProp,
392
+ destringified[prop]
393
+ );
391
394
  } else {
392
395
  destringified[prop] = objProp;
393
396
  }
394
397
  }
395
398
  return destringified;
396
399
  };
397
- const stringToObject = (str, opts = { verbose: true }) => {
400
+ const evalStringToObject = (str, opts = { verbose: true }) => {
398
401
  try {
399
- return str ? window.eval("(" + str + ")") : {};
402
+ return str ? (opts.window || window).eval("(" + str + ")") : {};
400
403
  } catch (e) {
401
404
  if (opts.verbose) console.warn(e);
402
- if (opts.errorCallback) return opts.errorCallback(e);
405
+ if (opts.onError) return opts.onError(e);
403
406
  }
404
407
  };
405
408
  const diffObjects = (original, objToDiff, cache, opts) => {
406
409
  let hasDiff = false;
407
- const allKeys = /* @__PURE__ */ new Set([...Object.keys(original), ...Object.keys(objToDiff)]);
410
+ const originalKeys = Object.keys(original);
411
+ const diffKeys = Object.keys(objToDiff);
412
+ const allKeys = [.../* @__PURE__ */ new Set([...originalKeys, ...diffKeys])];
413
+ const originalKeyOrder = originalKeys.join(",");
414
+ const diffKeyOrder = diffKeys.filter((k) => originalKeys.includes(k)).join(",");
415
+ if (originalKeyOrder !== diffKeyOrder) {
416
+ hasDiff = true;
417
+ }
408
418
  for (const key of allKeys) {
409
419
  if (key === "ref") continue;
410
420
  const originalProp = original[key];
@@ -438,6 +448,11 @@ const diffArrays = (original, objToDiff, cache, opts) => {
438
448
  return objToDiff;
439
449
  }
440
450
  let hasDiff = false;
451
+ const originalStringified = original.map((item) => JSON.stringify(item));
452
+ const diffStringified = objToDiff.map((item) => JSON.stringify(item));
453
+ if (originalStringified.join(",") !== diffStringified.join(",")) {
454
+ hasDiff = true;
455
+ }
441
456
  for (let i = 0; i < original.length; i++) {
442
457
  const diffObj = diff(original[i], objToDiff[i], {}, opts);
443
458
  if (diffObj && (isObject(diffObj) ? Object.keys(diffObj).length > 0 : true)) {
@@ -445,15 +460,15 @@ const diffArrays = (original, objToDiff, cache, opts) => {
445
460
  hasDiff = true;
446
461
  }
447
462
  }
448
- return hasDiff ? cache : void 0;
463
+ return hasDiff ? objToDiff : void 0;
449
464
  };
450
465
  const diff = (original, objToDiff, cache = {}, opts = {}) => {
451
466
  if (opts.cloneInstances) {
452
467
  original = deepClone(original);
453
468
  objToDiff = deepClone(objToDiff);
454
469
  }
455
- original = deepStringify(original);
456
- objToDiff = deepStringify(objToDiff);
470
+ original = deepStringifyFunctions(original);
471
+ objToDiff = deepStringifyFunctions(objToDiff);
457
472
  if (isArray(original) && isArray(objToDiff)) {
458
473
  const result = diffArrays(original, objToDiff, [], opts);
459
474
  return result === void 0 ? {} : result;
@@ -761,15 +776,16 @@ export {
761
776
  createObjectWithoutPrototype,
762
777
  deepClone,
763
778
  deepContains,
764
- deepDestringify,
779
+ deepDestringifyFunctions,
765
780
  deepDiff,
766
781
  deepMerge,
767
- deepStringify,
768
- deepStringifyWithMaxDepth,
782
+ deepStringifyFunctions,
783
+ deepStringifyFunctionsWithMaxDepth,
769
784
  detachFunctionsFromObject,
770
785
  detectInfiniteLoop,
771
786
  diff,
772
787
  diffObjects,
788
+ evalStringToObject,
773
789
  excludeKeysFromObject,
774
790
  exec,
775
791
  flattenRecursive,
@@ -791,6 +807,5 @@ export {
791
807
  overwriteShallow,
792
808
  removeFromObject,
793
809
  removeNestedKeyByPath,
794
- setInObjectByPath,
795
- stringToObject
810
+ setInObjectByPath
796
811
  };
package/object.js CHANGED
@@ -208,7 +208,7 @@ export const deepClone = (obj, options = {}) => {
208
208
  /**
209
209
  * Stringify object
210
210
  */
211
- export const deepStringify = (obj, stringified = {}) => {
211
+ export const deepStringifyFunctions = (obj, stringified = {}) => {
212
212
  if (!obj) return
213
213
  if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
214
214
  ;(obj.__element || obj.parent?.__element).warn(
@@ -224,13 +224,13 @@ export const deepStringify = (obj, stringified = {}) => {
224
224
  stringified[prop] = objProp.toString()
225
225
  } else if (isObject(objProp)) {
226
226
  stringified[prop] = {}
227
- deepStringify(objProp, stringified[prop])
227
+ deepStringifyFunctions(objProp, stringified[prop])
228
228
  } else if (isArray(objProp)) {
229
229
  stringified[prop] = []
230
230
  objProp.forEach((v, i) => {
231
231
  if (isObject(v)) {
232
232
  stringified[prop][i] = {}
233
- deepStringify(v, stringified[prop][i])
233
+ deepStringifyFunctions(v, stringified[prop][i])
234
234
  } else if (isFunction(v)) {
235
235
  stringified[prop][i] = v.toString()
236
236
  } else {
@@ -246,7 +246,7 @@ export const deepStringify = (obj, stringified = {}) => {
246
246
  }
247
247
 
248
248
  const MAX_DEPTH = 100 // Adjust this value as needed
249
- export const deepStringifyWithMaxDepth = (
249
+ export const deepStringifyFunctionsWithMaxDepth = (
250
250
  obj,
251
251
  stringified = {},
252
252
  depth = 0,
@@ -267,7 +267,7 @@ export const deepStringifyWithMaxDepth = (
267
267
  stringified[prop] = objProp.toString()
268
268
  } else if (isObject(objProp)) {
269
269
  stringified[prop] = {}
270
- deepStringifyWithMaxDepth(
270
+ deepStringifyFunctionsWithMaxDepth(
271
271
  objProp,
272
272
  stringified[prop],
273
273
  depth + 1,
@@ -279,7 +279,7 @@ export const deepStringifyWithMaxDepth = (
279
279
  const itemPath = `${currentPath}[${i}]`
280
280
  if (isObject(v)) {
281
281
  stringified[prop][i] = {}
282
- deepStringifyWithMaxDepth(
282
+ deepStringifyFunctionsWithMaxDepth(
283
283
  v,
284
284
  stringified[prop][i],
285
285
  depth + 1,
@@ -389,7 +389,7 @@ export const detachFunctionsFromObject = (obj, detached = {}) => {
389
389
  if (isFunction(objProp)) continue
390
390
  else if (isObject(objProp)) {
391
391
  detached[prop] = {}
392
- deepStringify(objProp, detached[prop])
392
+ deepStringifyFunctions(objProp, detached[prop])
393
393
  } else if (isArray(objProp)) {
394
394
  detached[prop] = []
395
395
  objProp.forEach((v, i) => {
@@ -440,7 +440,7 @@ export const hasFunction = (str) => {
440
440
  )
441
441
  }
442
442
 
443
- export const deepDestringify = (obj, destringified = {}) => {
443
+ export const deepDestringifyFunctions = (obj, destringified = {}) => {
444
444
  for (const prop in obj) {
445
445
  const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop)
446
446
  if (!hasOwnProperty) continue
@@ -473,13 +473,16 @@ export const deepDestringify = (obj, destringified = {}) => {
473
473
  destringified[prop].push(arrProp)
474
474
  }
475
475
  } else if (isObject(arrProp)) {
476
- destringified[prop].push(deepDestringify(arrProp))
476
+ destringified[prop].push(deepDestringifyFunctions(arrProp))
477
477
  } else {
478
478
  destringified[prop].push(arrProp)
479
479
  }
480
480
  })
481
481
  } else if (isObject(objProp)) {
482
- destringified[prop] = deepDestringify(objProp, destringified[prop])
482
+ destringified[prop] = deepDestringifyFunctions(
483
+ objProp,
484
+ destringified[prop]
485
+ )
483
486
  } else {
484
487
  destringified[prop] = objProp
485
488
  }
@@ -487,20 +490,31 @@ export const deepDestringify = (obj, destringified = {}) => {
487
490
  return destringified
488
491
  }
489
492
 
490
- export const stringToObject = (str, opts = { verbose: true }) => {
493
+ export const evalStringToObject = (str, opts = { verbose: true }) => {
491
494
  try {
492
- return str ? window.eval('(' + str + ')') : {} // eslint-disable-line
495
+ return str ? (opts.window || window).eval('(' + str + ')') : {} // eslint-disable-line
493
496
  } catch (e) {
494
497
  if (opts.verbose) console.warn(e)
495
- if (opts.errorCallback) return opts.errorCallback(e)
498
+ if (opts.onError) return opts.onError(e)
496
499
  }
497
500
  }
498
501
 
499
502
  export const diffObjects = (original, objToDiff, cache, opts) => {
500
503
  let hasDiff = false
501
504
 
502
- // Use union of keys
503
- const allKeys = new Set([...Object.keys(original), ...Object.keys(objToDiff)])
505
+ // Use union of keys maintaining original order where possible
506
+ const originalKeys = Object.keys(original)
507
+ const diffKeys = Object.keys(objToDiff)
508
+ const allKeys = [...new Set([...originalKeys, ...diffKeys])]
509
+
510
+ // Check if key order has changed
511
+ const originalKeyOrder = originalKeys.join(',')
512
+ const diffKeyOrder = diffKeys
513
+ .filter((k) => originalKeys.includes(k))
514
+ .join(',')
515
+ if (originalKeyOrder !== diffKeyOrder) {
516
+ hasDiff = true
517
+ }
504
518
 
505
519
  for (const key of allKeys) {
506
520
  if (key === 'ref') continue
@@ -537,11 +551,23 @@ export const diffObjects = (original, objToDiff, cache, opts) => {
537
551
  }
538
552
 
539
553
  const diffArrays = (original, objToDiff, cache, opts) => {
554
+ // Different lengths means arrays are different
540
555
  if (original.length !== objToDiff.length) {
541
556
  return objToDiff
542
557
  }
543
558
 
544
559
  let hasDiff = false
560
+
561
+ // First check if any elements have changed position
562
+ // by doing a shallow comparison of elements
563
+ const originalStringified = original.map((item) => JSON.stringify(item))
564
+ const diffStringified = objToDiff.map((item) => JSON.stringify(item))
565
+
566
+ if (originalStringified.join(',') !== diffStringified.join(',')) {
567
+ hasDiff = true
568
+ }
569
+
570
+ // Then do deep comparison of each element
545
571
  for (let i = 0; i < original.length; i++) {
546
572
  const diffObj = diff(original[i], objToDiff[i], {}, opts)
547
573
  if (
@@ -553,7 +579,7 @@ const diffArrays = (original, objToDiff, cache, opts) => {
553
579
  }
554
580
  }
555
581
 
556
- return hasDiff ? cache : undefined
582
+ return hasDiff ? objToDiff : undefined
557
583
  }
558
584
 
559
585
  export const diff = (original, objToDiff, cache = {}, opts = {}) => {
@@ -562,8 +588,8 @@ export const diff = (original, objToDiff, cache = {}, opts = {}) => {
562
588
  objToDiff = deepClone(objToDiff)
563
589
  }
564
590
 
565
- original = deepStringify(original)
566
- objToDiff = deepStringify(objToDiff)
591
+ original = deepStringifyFunctions(original)
592
+ objToDiff = deepStringifyFunctions(objToDiff)
567
593
 
568
594
  if (isArray(original) && isArray(objToDiff)) {
569
595
  const result = diffArrays(original, objToDiff, [], opts)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.31.26",
3
+ "version": "2.31.27",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -24,7 +24,7 @@
24
24
  "build": "npx 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": "126577d65a218af7e2f66b0a3f9691942ee8b9d2",
27
+ "gitHead": "0edcd5aae5c16b6a53a7e9b6512bb2562e8eb8a1",
28
28
  "devDependencies": {
29
29
  "@babel/core": "^7.27.1"
30
30
  }