@domql/utils 2.5.156 → 2.5.159

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.
@@ -0,0 +1,687 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import { window } from "./globals.js";
18
+ import {
19
+ isFunction,
20
+ isObjectLike,
21
+ isObject,
22
+ isArray,
23
+ isString,
24
+ is,
25
+ isUndefined,
26
+ isDate,
27
+ isNull
28
+ } from "./types.js";
29
+ import { mergeAndCloneIfArray, mergeArray } from "./array.js";
30
+ import { stringIncludesAny } from "./string.js";
31
+ import { isDOMNode } from "./node.js";
32
+ const ENV = "development";
33
+ const exec = (param, element, state, context) => {
34
+ if (isFunction(param)) {
35
+ return param.call(
36
+ element,
37
+ element,
38
+ state || element.state,
39
+ context || element.context
40
+ );
41
+ }
42
+ return param;
43
+ };
44
+ const map = (obj, extention, element) => {
45
+ for (const e in extention) {
46
+ obj[e] = exec(extention[e], element);
47
+ }
48
+ };
49
+ const merge = (element, obj, excludeFrom = []) => {
50
+ for (const e in obj) {
51
+ const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, e);
52
+ if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
53
+ continue;
54
+ const elementProp = element[e];
55
+ const objProp = obj[e];
56
+ if (elementProp === void 0) {
57
+ element[e] = objProp;
58
+ }
59
+ }
60
+ return element;
61
+ };
62
+ const deepMerge = (element, extend, excludeFrom = []) => {
63
+ for (const e in extend) {
64
+ const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(extend, e);
65
+ if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
66
+ continue;
67
+ const elementProp = element[e];
68
+ const extendProp = extend[e];
69
+ if (isObjectLike(elementProp) && isObjectLike(extendProp)) {
70
+ deepMerge(elementProp, extendProp, excludeFrom);
71
+ } else if (elementProp === void 0) {
72
+ element[e] = extendProp;
73
+ }
74
+ }
75
+ return element;
76
+ };
77
+ const clone = (obj, excludeFrom = []) => {
78
+ const o = {};
79
+ for (const prop in obj) {
80
+ const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
81
+ if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__"))
82
+ continue;
83
+ o[prop] = obj[prop];
84
+ }
85
+ return o;
86
+ };
87
+ const deepCloneExclude = (obj, excludeFrom = []) => {
88
+ if (isArray(obj)) {
89
+ return obj.map((x) => deepCloneExclude(x, excludeFrom));
90
+ }
91
+ const o = {};
92
+ for (const k in obj) {
93
+ const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, k);
94
+ if (!hasOwnProperty2 || excludeFrom.includes(k) || k.startsWith("__"))
95
+ continue;
96
+ let v = obj[k];
97
+ if (k === "extend" && isArray(v)) {
98
+ v = mergeArrayExclude(v, excludeFrom);
99
+ }
100
+ if (isArray(v)) {
101
+ o[k] = v.map((x) => deepCloneExclude(x, excludeFrom));
102
+ } else if (isObject(v)) {
103
+ o[k] = deepCloneExclude(v, excludeFrom);
104
+ } else
105
+ o[k] = v;
106
+ }
107
+ return o;
108
+ };
109
+ const mergeArrayExclude = (arr, excl = []) => {
110
+ return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
111
+ };
112
+ const deepClone = (obj, exclude = [], cleanUndefined = false, visited = /* @__PURE__ */ new WeakMap()) => {
113
+ if (!isObjectLike(obj) || isDOMNode(obj))
114
+ return obj;
115
+ if (visited.has(obj))
116
+ return visited.get(obj);
117
+ const clone2 = isArray(obj) ? [] : {};
118
+ visited.set(obj, clone2);
119
+ for (const key in obj) {
120
+ if (Object.prototype.hasOwnProperty.call(obj, key) && !exclude.includes(key)) {
121
+ const value = obj[key];
122
+ if (isDOMNode(value)) {
123
+ clone2[key] = value;
124
+ } else if (key === "extend" && isArray(value)) {
125
+ clone2[key] = mergeArray(value, exclude);
126
+ } else if (isObjectLike(value)) {
127
+ clone2[key] = deepClone(value, exclude, cleanUndefined, visited);
128
+ } else {
129
+ clone2[key] = value;
130
+ }
131
+ }
132
+ }
133
+ return clone2;
134
+ };
135
+ const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => {
136
+ if (isObjectLike(obj)) {
137
+ if (visited.has(obj)) {
138
+ return obj;
139
+ }
140
+ visited.add(obj);
141
+ }
142
+ const o = options.window ? isArray(obj) ? new options.window.Array([]) : new options.window.Object({}) : isArray(obj) ? [] : {};
143
+ for (const prop in obj) {
144
+ if (!Object.prototype.hasOwnProperty.call(obj, prop))
145
+ continue;
146
+ const objProp = obj[prop];
147
+ if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && isUndefined(objProp) || options.cleanNull && isNull(objProp)) {
148
+ continue;
149
+ }
150
+ if (isObjectLike(objProp)) {
151
+ o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited);
152
+ } else if (isFunction(objProp) && options.window) {
153
+ o[prop] = (options.window || window).eval("(" + objProp.toString() + ")");
154
+ } else {
155
+ o[prop] = objProp;
156
+ }
157
+ }
158
+ return o;
159
+ };
160
+ const deepStringify = (obj, stringified = {}) => {
161
+ var _a, _b;
162
+ if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
163
+ (obj.__element || ((_a = obj.parent) == null ? void 0 : _a.__element)).warn("Trying to clone element or state at", obj);
164
+ obj = (_b = obj.parse) == null ? void 0 : _b.call(obj);
165
+ }
166
+ for (const prop in obj) {
167
+ const objProp = obj[prop];
168
+ if (isFunction(objProp)) {
169
+ stringified[prop] = objProp.toString();
170
+ } else if (isObject(objProp)) {
171
+ stringified[prop] = {};
172
+ deepStringify(objProp, stringified[prop]);
173
+ } else if (isArray(objProp)) {
174
+ stringified[prop] = [];
175
+ objProp.forEach((v, i) => {
176
+ if (isObject(v)) {
177
+ stringified[prop][i] = {};
178
+ deepStringify(v, stringified[prop][i]);
179
+ } else if (isFunction(v)) {
180
+ stringified[prop][i] = v.toString();
181
+ } else {
182
+ stringified[prop][i] = v;
183
+ }
184
+ });
185
+ } else {
186
+ stringified[prop] = objProp;
187
+ }
188
+ }
189
+ return stringified;
190
+ };
191
+ const MAX_DEPTH = 100;
192
+ const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
193
+ if (depth > MAX_DEPTH) {
194
+ console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`);
195
+ return "[MAX_DEPTH_EXCEEDED]";
196
+ }
197
+ for (const prop in obj) {
198
+ const currentPath = path ? `${path}.${prop}` : prop;
199
+ const objProp = obj[prop];
200
+ if (isFunction(objProp)) {
201
+ stringified[prop] = objProp.toString();
202
+ } else if (isObject(objProp)) {
203
+ stringified[prop] = {};
204
+ deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath);
205
+ } else if (isArray(objProp)) {
206
+ stringified[prop] = [];
207
+ objProp.forEach((v, i) => {
208
+ const itemPath = `${currentPath}[${i}]`;
209
+ if (isObject(v)) {
210
+ stringified[prop][i] = {};
211
+ deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath);
212
+ } else if (isFunction(v)) {
213
+ stringified[prop][i] = v.toString();
214
+ } else {
215
+ stringified[prop][i] = v;
216
+ }
217
+ });
218
+ } else {
219
+ stringified[prop] = objProp;
220
+ }
221
+ }
222
+ return stringified;
223
+ };
224
+ const objectToString = (obj = {}, indent = 0) => {
225
+ const spaces = " ".repeat(indent);
226
+ let str = "{\n";
227
+ for (const [key, value] of Object.entries(obj)) {
228
+ const keyNotAllowdChars = stringIncludesAny(key, ["&", "*", "-", ":", "%", "{", "}", ">", "<", "@", ".", "/", "!", " "]);
229
+ const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
230
+ str += `${spaces} ${stringedKey}: `;
231
+ if (isArray(value)) {
232
+ str += "[\n";
233
+ for (const element of value) {
234
+ if (isObjectLike(element) && element !== null) {
235
+ str += `${spaces} ${objectToString(element, indent + 2)},
236
+ `;
237
+ } else if (isString(element)) {
238
+ str += `${spaces} '${element}',
239
+ `;
240
+ } else {
241
+ str += `${spaces} ${element},
242
+ `;
243
+ }
244
+ }
245
+ str += `${spaces} ]`;
246
+ } else if (isObjectLike(value)) {
247
+ str += objectToString(value, indent + 1);
248
+ } else if (isString(value)) {
249
+ str += stringIncludesAny(value, ["\n", "'"]) ? `\`${value}\`` : `'${value}'`;
250
+ } else {
251
+ str += value;
252
+ }
253
+ str += ",\n";
254
+ }
255
+ str += `${spaces}}`;
256
+ return str;
257
+ };
258
+ const detachFunctionsFromObject = (obj, detached = {}) => {
259
+ for (const prop in obj) {
260
+ const objProp = obj[prop];
261
+ if (isFunction(objProp))
262
+ continue;
263
+ else if (isObject(objProp)) {
264
+ detached[prop] = {};
265
+ deepStringify(objProp, detached[prop]);
266
+ } else if (isArray(objProp)) {
267
+ detached[prop] = [];
268
+ objProp.forEach((v, i) => {
269
+ if (isFunction(v))
270
+ return;
271
+ if (isObject(v)) {
272
+ detached[prop][i] = {};
273
+ detachFunctionsFromObject(v, detached[prop][i]);
274
+ } else {
275
+ detached[prop][i] = v;
276
+ }
277
+ });
278
+ } else {
279
+ detached[prop] = objProp;
280
+ }
281
+ }
282
+ return detached;
283
+ };
284
+ const deepDestringify = (obj, destringified = {}) => {
285
+ for (const prop in obj) {
286
+ const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
287
+ if (!hasOwnProperty2)
288
+ continue;
289
+ const objProp = obj[prop];
290
+ if (isString(objProp)) {
291
+ if ((objProp.includes("(){") || objProp.includes("() {") || objProp.includes("=>") || objProp.startsWith("()") || objProp.startsWith("async") || objProp.startsWith("function") || objProp.startsWith("(")) && !objProp.startsWith("{") && !objProp.startsWith("[")) {
292
+ try {
293
+ const evalProp = window.eval(`(${objProp})`);
294
+ destringified[prop] = evalProp;
295
+ } catch (e) {
296
+ if (e)
297
+ destringified[prop] = objProp;
298
+ }
299
+ } else {
300
+ destringified[prop] = objProp;
301
+ }
302
+ } else if (isArray(objProp)) {
303
+ destringified[prop] = [];
304
+ objProp.forEach((arrProp) => {
305
+ if (isString(arrProp)) {
306
+ if (arrProp.includes("=>") || arrProp.includes("function") || arrProp.startsWith("(")) {
307
+ try {
308
+ const evalProp = window.eval(`(${arrProp})`);
309
+ destringified[prop].push(evalProp);
310
+ } catch (e) {
311
+ if (e)
312
+ destringified[prop].push(arrProp);
313
+ }
314
+ } else {
315
+ destringified[prop].push(arrProp);
316
+ }
317
+ } else if (isObject(arrProp)) {
318
+ destringified[prop].push(deepDestringify(arrProp));
319
+ } else {
320
+ destringified[prop].push(arrProp);
321
+ }
322
+ });
323
+ } else if (isObject(objProp)) {
324
+ destringified[prop] = deepDestringify(objProp, destringified[prop]);
325
+ } else {
326
+ destringified[prop] = objProp;
327
+ }
328
+ }
329
+ return destringified;
330
+ };
331
+ const stringToObject = (str, opts = { verbose: true }) => {
332
+ try {
333
+ return str ? window.eval("(" + str + ")") : {};
334
+ } catch (e) {
335
+ if (opts.verbose)
336
+ console.warn(e);
337
+ }
338
+ };
339
+ const diffObjects = (original, objToDiff, cache) => {
340
+ for (const e in objToDiff) {
341
+ if (e === "ref")
342
+ continue;
343
+ const originalProp = original[e];
344
+ const objToDiffProp = objToDiff[e];
345
+ if (isObject(originalProp) && isObject(objToDiffProp)) {
346
+ cache[e] = {};
347
+ diff(originalProp, objToDiffProp, cache[e]);
348
+ } else if (objToDiffProp !== void 0) {
349
+ cache[e] = objToDiffProp;
350
+ }
351
+ }
352
+ return cache;
353
+ };
354
+ const diffArrays = (original, objToDiff, cache) => {
355
+ if (original.length !== objToDiff.length) {
356
+ cache = objToDiff;
357
+ } else {
358
+ const diffArr = [];
359
+ for (let i = 0; i < original.length; i++) {
360
+ const diffObj = diff(original[i], objToDiff[i]);
361
+ if (Object.keys(diffObj).length > 0) {
362
+ diffArr.push(diffObj);
363
+ }
364
+ }
365
+ if (diffArr.length > 0) {
366
+ cache = diffArr;
367
+ }
368
+ }
369
+ return cache;
370
+ };
371
+ const diff = (original, objToDiff, cache = {}) => {
372
+ if (isArray(original) && isArray(objToDiff)) {
373
+ cache = [];
374
+ diffArrays(original, objToDiff, cache);
375
+ } else {
376
+ diffObjects(original, objToDiff, cache);
377
+ }
378
+ return cache;
379
+ };
380
+ const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args);
381
+ const isEmpty = (o) => Object.keys(o).length === 0;
382
+ const isEmptyObject = (o) => isObject(o) && isEmpty(o);
383
+ const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
384
+ const deepDiff = (lhs, rhs) => {
385
+ if (lhs === rhs)
386
+ return {};
387
+ if (!isObjectLike(lhs) || !isObjectLike(rhs))
388
+ return rhs;
389
+ const deletedValues = Object.keys(lhs).reduce((acc, key) => {
390
+ if (!hasOwnProperty(rhs, key)) {
391
+ acc[key] = void 0;
392
+ }
393
+ return acc;
394
+ }, makeObjectWithoutPrototype());
395
+ if (isDate(lhs) || isDate(rhs)) {
396
+ if (lhs.valueOf() === rhs.valueOf())
397
+ return {};
398
+ return rhs;
399
+ }
400
+ return Object.keys(rhs).reduce((acc, key) => {
401
+ if (!hasOwnProperty(lhs, key)) {
402
+ acc[key] = rhs[key];
403
+ return acc;
404
+ }
405
+ const difference = diff(lhs[key], rhs[key]);
406
+ if (isEmptyObject(difference) && !isDate(difference) && (isEmptyObject(lhs[key]) || !isEmptyObject(rhs[key]))) {
407
+ return acc;
408
+ }
409
+ acc[key] = difference;
410
+ return acc;
411
+ }, deletedValues);
412
+ };
413
+ const overwrite = (element, params, opts = {}) => {
414
+ const { __ref: ref } = element;
415
+ const excl = opts.exclude || [];
416
+ const allowUnderscore = opts.preventUnderscore;
417
+ const preventCaching = opts.preventCaching;
418
+ for (const e in params) {
419
+ if (excl.includes(e) || !allowUnderscore && e.startsWith("__"))
420
+ continue;
421
+ const elementProp = element[e];
422
+ const paramsProp = params[e];
423
+ if (paramsProp !== void 0) {
424
+ element[e] = paramsProp;
425
+ if (ref && !preventCaching) {
426
+ ref.__cache[e] = elementProp;
427
+ }
428
+ if (isObject(opts.diff)) {
429
+ diff[e] = elementProp;
430
+ }
431
+ }
432
+ }
433
+ return element;
434
+ };
435
+ const overwriteShallow = (obj, params, excludeFrom = []) => {
436
+ for (const e in params) {
437
+ if (excludeFrom.includes(e) || e.startsWith("__"))
438
+ continue;
439
+ obj[e] = params[e];
440
+ }
441
+ return obj;
442
+ };
443
+ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new WeakMap()) => {
444
+ const excl = opts.exclude || [];
445
+ const forcedExclude = opts.preventForce ? [] : ["node", "window"];
446
+ if (!isObjectLike(obj) || !isObjectLike(params) || isDOMNode(obj) || isDOMNode(params)) {
447
+ return params;
448
+ }
449
+ if (visited.has(obj))
450
+ return visited.get(obj);
451
+ visited.set(obj, obj);
452
+ for (const e in params) {
453
+ if (!Object.hasOwnProperty.call(params, e))
454
+ continue;
455
+ if (excl.includes(e) || forcedExclude && e.startsWith("__"))
456
+ continue;
457
+ const objProp = obj[e];
458
+ const paramsProp = params[e];
459
+ if (isDOMNode(paramsProp)) {
460
+ obj[e] = paramsProp;
461
+ } else if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
462
+ obj[e] = overwriteDeep(objProp, paramsProp, opts, visited);
463
+ } else if (paramsProp !== void 0) {
464
+ obj[e] = paramsProp;
465
+ }
466
+ }
467
+ return obj;
468
+ };
469
+ const mergeIfExisted = (a, b) => {
470
+ if (isObjectLike(a) && isObjectLike(b))
471
+ return deepMerge(a, b);
472
+ return a || b;
473
+ };
474
+ const flattenRecursive = (param, prop, stack = []) => {
475
+ const objectized = mergeAndCloneIfArray(param);
476
+ stack.push(objectized);
477
+ const extendOfExtend = objectized[prop];
478
+ if (extendOfExtend)
479
+ flattenRecursive(extendOfExtend, prop, stack);
480
+ delete objectized[prop];
481
+ return stack;
482
+ };
483
+ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
484
+ if (typeof param !== "object" || typeof element !== "object" || param === null || element === null) {
485
+ return param === element;
486
+ }
487
+ if (visited.has(param) || visited.has(element)) {
488
+ return true;
489
+ }
490
+ visited.add(param);
491
+ visited.add(element);
492
+ const keysParam = Object.keys(param);
493
+ const keysElement = Object.keys(element);
494
+ if (keysParam.length !== keysElement.length) {
495
+ return false;
496
+ }
497
+ for (const key of keysParam) {
498
+ if (!keysElement.includes(key)) {
499
+ return false;
500
+ }
501
+ const paramProp = param[key];
502
+ const elementProp = element[key];
503
+ if (!isEqualDeep(paramProp, elementProp, visited)) {
504
+ return false;
505
+ }
506
+ }
507
+ return true;
508
+ };
509
+ const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
510
+ if (obj1 === obj2)
511
+ return true;
512
+ if (!isObjectLike(obj1) || !isObjectLike(obj2))
513
+ return false;
514
+ if (isDOMNode(obj1) || isDOMNode(obj2))
515
+ return obj1 === obj2;
516
+ const stack = [[obj1, obj2]];
517
+ const visited = /* @__PURE__ */ new WeakSet();
518
+ while (stack.length > 0) {
519
+ const [current1, current2] = stack.pop();
520
+ if (visited.has(current1))
521
+ continue;
522
+ visited.add(current1);
523
+ const keys1 = Object.keys(current1).filter((key) => !ignoredKeys.includes(key));
524
+ const keys2 = Object.keys(current2).filter((key) => !ignoredKeys.includes(key));
525
+ if (keys1.length !== keys2.length)
526
+ return false;
527
+ for (const key of keys1) {
528
+ if (!Object.prototype.hasOwnProperty.call(current2, key))
529
+ return false;
530
+ const value1 = current1[key];
531
+ const value2 = current2[key];
532
+ if (isDOMNode(value1) || isDOMNode(value2)) {
533
+ if (value1 !== value2)
534
+ return false;
535
+ } else if (isObjectLike(value1) && isObjectLike(value2)) {
536
+ if (value1 !== value2) {
537
+ stack.push([value1, value2]);
538
+ }
539
+ } else if (value1 !== value2) {
540
+ return false;
541
+ }
542
+ }
543
+ }
544
+ return true;
545
+ };
546
+ const removeFromObject = (obj, props) => {
547
+ if (props === void 0 || props === null)
548
+ return obj;
549
+ if (is(props)("string", "number")) {
550
+ delete obj[props];
551
+ } else if (isArray(props)) {
552
+ props.forEach((prop) => delete obj[prop]);
553
+ } else {
554
+ throw new Error("Invalid input: props must be a string or an array of strings");
555
+ }
556
+ return obj;
557
+ };
558
+ const createObjectWithoutPrototype = (obj) => {
559
+ if (obj === null || typeof obj !== "object") {
560
+ return obj;
561
+ }
562
+ const newObj = /* @__PURE__ */ Object.create(null);
563
+ for (const key in obj) {
564
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
565
+ newObj[key] = createObjectWithoutPrototype(obj[key]);
566
+ }
567
+ }
568
+ return newObj;
569
+ };
570
+ const createNestedObject = (arr, lastValue) => {
571
+ const nestedObject = {};
572
+ if (arr.length === 0) {
573
+ return lastValue;
574
+ }
575
+ arr.reduce((obj, value, index) => {
576
+ if (!obj[value]) {
577
+ obj[value] = {};
578
+ }
579
+ if (index === arr.length - 1 && lastValue) {
580
+ obj[value] = lastValue;
581
+ }
582
+ return obj[value];
583
+ }, nestedObject);
584
+ return nestedObject;
585
+ };
586
+ const removeNestedKeyByPath = (obj, path) => {
587
+ if (!Array.isArray(path)) {
588
+ throw new Error("Path must be an array.");
589
+ }
590
+ let current = obj;
591
+ for (let i = 0; i < path.length - 1; i++) {
592
+ if (current[path[i]] === void 0) {
593
+ return;
594
+ }
595
+ current = current[path[i]];
596
+ }
597
+ const lastKey = path[path.length - 1];
598
+ if (current && Object.hasOwnProperty.call(current, lastKey)) {
599
+ delete current[lastKey];
600
+ }
601
+ };
602
+ const detectInfiniteLoop = (arr) => {
603
+ const maxRepeats = 10;
604
+ let pattern = [];
605
+ let repeatCount = 0;
606
+ for (let i = 0; i < arr.length; i++) {
607
+ if (pattern.length < 2) {
608
+ pattern.push(arr[i]);
609
+ } else {
610
+ if (arr[i] === pattern[i % 2]) {
611
+ repeatCount++;
612
+ } else {
613
+ pattern = [arr[i - 1], arr[i]];
614
+ repeatCount = 1;
615
+ }
616
+ if (repeatCount >= maxRepeats * 2) {
617
+ if (ENV === "test" || ENV === "development") {
618
+ console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern);
619
+ }
620
+ return true;
621
+ }
622
+ }
623
+ }
624
+ };
625
+ const isCyclic = (obj) => {
626
+ const seenObjects = [];
627
+ function detect(obj2) {
628
+ if (obj2 && typeof obj2 === "object") {
629
+ if (seenObjects.indexOf(obj2) !== -1) {
630
+ return true;
631
+ }
632
+ seenObjects.push(obj2);
633
+ for (const key in obj2) {
634
+ if (Object.hasOwnProperty.call(obj2, key) && detect(obj2[key])) {
635
+ console.log(obj2, "cycle at " + key);
636
+ return true;
637
+ }
638
+ }
639
+ }
640
+ return false;
641
+ }
642
+ return detect(obj);
643
+ };
644
+ const excludeKeysFromObject = (obj, excludedKeys) => {
645
+ const result = __spreadValues({}, obj);
646
+ excludedKeys.forEach((key) => delete result[key]);
647
+ return result;
648
+ };
649
+ export {
650
+ clone,
651
+ createNestedObject,
652
+ createObjectWithoutPrototype,
653
+ deepClone,
654
+ deepCloneExclude,
655
+ deepCloneWithExtend,
656
+ deepContains,
657
+ deepDestringify,
658
+ deepDiff,
659
+ deepMerge,
660
+ deepStringify,
661
+ deepStringifyWithMaxDepth,
662
+ detachFunctionsFromObject,
663
+ detectInfiniteLoop,
664
+ diff,
665
+ diffArrays,
666
+ diffObjects,
667
+ excludeKeysFromObject,
668
+ exec,
669
+ flattenRecursive,
670
+ hasOwnProperty,
671
+ isCyclic,
672
+ isEmpty,
673
+ isEmptyObject,
674
+ isEqualDeep,
675
+ makeObjectWithoutPrototype,
676
+ map,
677
+ merge,
678
+ mergeArrayExclude,
679
+ mergeIfExisted,
680
+ objectToString,
681
+ overwrite,
682
+ overwriteDeep,
683
+ overwriteShallow,
684
+ removeFromObject,
685
+ removeNestedKeyByPath,
686
+ stringToObject
687
+ };