@domql/utils 2.29.51 → 2.29.53

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.
@@ -79,10 +79,8 @@ function exec(param, element, state, context) {
79
79
  }
80
80
  return result;
81
81
  } catch (e) {
82
- if ((0, import_env.isNotProduction)()) {
83
- console.log(param);
84
- console.warn("Error executing function", e);
85
- }
82
+ element.log(param);
83
+ element.warn("Error executing function", e);
86
84
  }
87
85
  }
88
86
  return param;
@@ -188,7 +186,6 @@ const deepClone = (obj, options = {}) => {
188
186
  const deepStringify = (obj, stringified = {}) => {
189
187
  var _a, _b;
190
188
  if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
191
- ;
192
189
  (obj.__element || ((_a = obj.parent) == null ? void 0 : _a.__element)).warn(
193
190
  "Trying to clone element or state at",
194
191
  obj
@@ -48,10 +48,8 @@ function exec(param, element, state, context) {
48
48
  }
49
49
  return result;
50
50
  } catch (e) {
51
- if (isNotProduction()) {
52
- console.log(param);
53
- console.warn("Error executing function", e);
54
- }
51
+ element.log(param);
52
+ element.warn("Error executing function", e);
55
53
  }
56
54
  }
57
55
  return param;
@@ -156,7 +154,6 @@ const deepClone = (obj, options = {}) => {
156
154
  const deepStringify = (obj, stringified = {}) => {
157
155
  var _a, _b;
158
156
  if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
159
- ;
160
157
  (obj.__element || ((_a = obj.parent) == null ? void 0 : _a.__element)).warn(
161
158
  "Trying to clone element or state at",
162
159
  obj
package/object.js CHANGED
@@ -1,6 +1,6 @@
1
- 'use strict'
1
+ "use strict";
2
2
 
3
- import { window } from './globals.js'
3
+ import { window } from "./globals.js";
4
4
  import {
5
5
  isFunction,
6
6
  isObjectLike,
@@ -10,12 +10,12 @@ import {
10
10
  is,
11
11
  isUndefined,
12
12
  isDate,
13
- isNull
14
- } from './types.js'
15
- import { mergeAndCloneIfArray, mergeArray } from './array.js'
16
- import { stringIncludesAny } from './string.js'
17
- import { isDOMNode } from './node.js'
18
- import { isNotProduction } from './env.js'
13
+ isNull,
14
+ } from "./types.js";
15
+ import { mergeAndCloneIfArray, mergeArray } from "./array.js";
16
+ import { stringIncludesAny } from "./string.js";
17
+ import { isDOMNode } from "./node.js";
18
+ import { isNotProduction } from "./env.js";
19
19
 
20
20
  /**
21
21
  * Executes a function with the specified context and parameters.
@@ -30,8 +30,8 @@ import { isNotProduction } from './env.js'
30
30
  * @param {Object} context - The context to pass to the function
31
31
  * @returns {any|Promise} - The result or a Promise to the result
32
32
  */
33
- export function exec (param, element, state, context) {
34
- if (!element) element = this
33
+ export function exec(param, element, state, context) {
34
+ if (!element) element = this;
35
35
  if (isFunction(param)) {
36
36
  try {
37
37
  // Call the function with the specified context and parameters
@@ -40,79 +40,77 @@ export function exec (param, element, state, context) {
40
40
  element,
41
41
  state || element.state,
42
42
  context || element.context
43
- )
43
+ );
44
44
 
45
45
  // Handle promises
46
- if (result && typeof result.then === 'function') {
46
+ if (result && typeof result.then === "function") {
47
47
  // This magic allows the function to be awaited if called with await
48
48
  // but still work reasonably when called without await
49
- return result
49
+ return result;
50
50
  }
51
- return result
51
+ return result;
52
52
  } catch (e) {
53
- if (isNotProduction()) {
54
- console.log(param)
55
- console.warn('Error executing function', e)
56
- }
53
+ element.log(param);
54
+ element.warn("Error executing function", e);
57
55
  }
58
56
  }
59
- return param
57
+ return param;
60
58
  }
61
59
 
62
60
  export const map = (obj, extention, element) => {
63
61
  for (const e in extention) {
64
- obj[e] = exec(extention[e], element)
62
+ obj[e] = exec(extention[e], element);
65
63
  }
66
- }
64
+ };
67
65
 
68
66
  export const merge = (element, obj, excludeFrom = []) => {
69
67
  for (const e in obj) {
70
- const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, e)
71
- if (!hasOwnProperty || excludeFrom.includes(e) || e.startsWith('__'))
72
- continue
73
- const elementProp = element[e]
74
- const objProp = obj[e]
68
+ const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, e);
69
+ if (!hasOwnProperty || excludeFrom.includes(e) || e.startsWith("__"))
70
+ continue;
71
+ const elementProp = element[e];
72
+ const objProp = obj[e];
75
73
  if (elementProp === undefined) {
76
- element[e] = objProp
74
+ element[e] = objProp;
77
75
  }
78
76
  }
79
- return element
80
- }
77
+ return element;
78
+ };
81
79
 
82
80
  export const deepMerge = (element, extend, excludeFrom = []) => {
83
81
  for (const e in extend) {
84
- const hasOwnProperty = Object.prototype.hasOwnProperty.call(extend, e)
85
- if (!hasOwnProperty || excludeFrom.includes(e) || e.startsWith('__'))
86
- continue
87
- const elementProp = element[e]
88
- const extendProp = extend[e]
82
+ const hasOwnProperty = Object.prototype.hasOwnProperty.call(extend, e);
83
+ if (!hasOwnProperty || excludeFrom.includes(e) || e.startsWith("__"))
84
+ continue;
85
+ const elementProp = element[e];
86
+ const extendProp = extend[e];
89
87
  if (isObjectLike(elementProp) && isObjectLike(extendProp)) {
90
- deepMerge(elementProp, extendProp, excludeFrom)
88
+ deepMerge(elementProp, extendProp, excludeFrom);
91
89
  } else if (elementProp === undefined) {
92
- element[e] = extendProp
90
+ element[e] = extendProp;
93
91
  }
94
92
  }
95
- return element
96
- }
93
+ return element;
94
+ };
97
95
 
98
96
  export const clone = (obj, excludeFrom = []) => {
99
- const o = {}
97
+ const o = {};
100
98
  for (const prop in obj) {
101
- const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop)
102
- if (!hasOwnProperty || excludeFrom.includes(prop) || prop.startsWith('__'))
103
- continue
104
- o[prop] = obj[prop]
99
+ const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop);
100
+ if (!hasOwnProperty || excludeFrom.includes(prop) || prop.startsWith("__"))
101
+ continue;
102
+ o[prop] = obj[prop];
105
103
  }
106
- return o
107
- }
104
+ return o;
105
+ };
108
106
 
109
107
  // Merge array, but exclude keys listed in 'excl'z
110
108
  export const mergeArrayExclude = (arr, exclude = []) => {
111
109
  return arr.reduce(
112
110
  (acc, curr) => deepMerge(acc, deepClone(curr, { exclude })),
113
111
  {}
114
- )
115
- }
112
+ );
113
+ };
116
114
  /**
117
115
  * Enhanced deep clone function that combines features from multiple implementations
118
116
  * @param {any} obj - Object to clone
@@ -132,19 +130,19 @@ export const deepClone = (obj, options = {}) => {
132
130
  cleanNull = false,
133
131
  window: targetWindow,
134
132
  visited = new WeakMap(),
135
- handleExtend = false
136
- } = options
133
+ handleExtend = false,
134
+ } = options;
137
135
 
138
- const contentWindow = targetWindow || window || globalThis
136
+ const contentWindow = targetWindow || window || globalThis;
139
137
 
140
138
  // Handle non-object types and special cases
141
139
  if (!isObjectLike(obj) || isDOMNode(obj)) {
142
- return obj
140
+ return obj;
143
141
  }
144
142
 
145
143
  // Handle circular references
146
144
  if (visited.has(obj)) {
147
- return visited.get(obj)
145
+ return visited.get(obj);
148
146
  }
149
147
 
150
148
  // Create appropriate container based on type and window context
@@ -153,250 +151,250 @@ export const deepClone = (obj, options = {}) => {
153
151
  ? new contentWindow.Array()
154
152
  : new contentWindow.Object()
155
153
  : isArray(obj)
156
- ? []
157
- : {}
154
+ ? []
155
+ : {};
158
156
 
159
157
  // Store the clone to handle circular references
160
- visited.set(obj, clone)
158
+ visited.set(obj, clone);
161
159
 
162
160
  // Clone properties
163
161
  for (const key in obj) {
164
- if (!Object.prototype.hasOwnProperty.call(obj, key)) continue
162
+ if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
165
163
 
166
164
  // Skip excluded properties
167
- if (exclude.includes(key) || key.startsWith('__') || key === '__proto__')
168
- continue
165
+ if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
166
+ continue;
169
167
 
170
- const value = obj[key]
168
+ const value = obj[key];
171
169
 
172
170
  // Skip based on cleanup options
173
171
  if ((cleanUndefined && isUndefined(value)) || (cleanNull && isNull(value)))
174
- continue
172
+ continue;
175
173
 
176
174
  // Handle special cases
177
175
  if (isDOMNode(value)) {
178
- clone[key] = value
179
- continue
176
+ clone[key] = value;
177
+ continue;
180
178
  }
181
179
 
182
180
  // Handle 'extend' array if enabled
183
- if (handleExtend && key === 'extend' && isArray(value)) {
184
- clone[key] = mergeArray(value, exclude)
185
- continue
181
+ if (handleExtend && key === "extend" && isArray(value)) {
182
+ clone[key] = mergeArray(value, exclude);
183
+ continue;
186
184
  }
187
185
 
188
186
  // Handle functions in cross-frame scenario
189
187
  if (isFunction(value) && options.window) {
190
- clone[key] = contentWindow.eval('(' + value.toString() + ')')
191
- continue
188
+ clone[key] = contentWindow.eval("(" + value.toString() + ")");
189
+ continue;
192
190
  }
193
191
 
194
192
  // Recursively clone objects
195
193
  if (isObjectLike(value)) {
196
- if (!Object.prototype.hasOwnProperty.call(obj, key)) continue
194
+ if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
197
195
 
198
196
  clone[key] = deepClone(value, {
199
197
  ...options,
200
- visited
201
- })
198
+ visited,
199
+ });
202
200
  } else {
203
- clone[key] = value
201
+ clone[key] = value;
204
202
  }
205
203
  }
206
204
 
207
- return clone
208
- }
205
+ return clone;
206
+ };
209
207
 
210
208
  /**
211
209
  * Stringify object
212
210
  */
213
211
  export const deepStringify = (obj, stringified = {}) => {
214
212
  if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
215
- ;(obj.__element || obj.parent?.__element).warn(
216
- 'Trying to clone element or state at',
213
+ (obj.__element || obj.parent?.__element).warn(
214
+ "Trying to clone element or state at",
217
215
  obj
218
- )
219
- obj = obj.parse?.()
216
+ );
217
+ obj = obj.parse?.();
220
218
  }
221
219
 
222
220
  for (const prop in obj) {
223
- const objProp = obj[prop]
221
+ const objProp = obj[prop];
224
222
  if (isFunction(objProp)) {
225
- stringified[prop] = objProp.toString()
223
+ stringified[prop] = objProp.toString();
226
224
  } else if (isObject(objProp)) {
227
- stringified[prop] = {}
228
- deepStringify(objProp, stringified[prop])
225
+ stringified[prop] = {};
226
+ deepStringify(objProp, stringified[prop]);
229
227
  } else if (isArray(objProp)) {
230
- stringified[prop] = []
228
+ stringified[prop] = [];
231
229
  objProp.forEach((v, i) => {
232
230
  if (isObject(v)) {
233
- stringified[prop][i] = {}
234
- deepStringify(v, stringified[prop][i])
231
+ stringified[prop][i] = {};
232
+ deepStringify(v, stringified[prop][i]);
235
233
  } else if (isFunction(v)) {
236
- stringified[prop][i] = v.toString()
234
+ stringified[prop][i] = v.toString();
237
235
  } else {
238
- stringified[prop][i] = v
236
+ stringified[prop][i] = v;
239
237
  }
240
- })
238
+ });
241
239
  } else {
242
- stringified[prop] = objProp
240
+ stringified[prop] = objProp;
243
241
  }
244
242
  }
245
- return stringified
246
- }
243
+ return stringified;
244
+ };
247
245
 
248
- const MAX_DEPTH = 100 // Adjust this value as needed
246
+ const MAX_DEPTH = 100; // Adjust this value as needed
249
247
  export const deepStringifyWithMaxDepth = (
250
248
  obj,
251
249
  stringified = {},
252
250
  depth = 0,
253
- path = ''
251
+ path = ""
254
252
  ) => {
255
253
  if (depth > MAX_DEPTH) {
256
254
  console.warn(
257
255
  `Maximum depth exceeded at path: ${path}. Possible circular reference.`
258
- )
259
- return '[MAX_DEPTH_EXCEEDED]'
256
+ );
257
+ return "[MAX_DEPTH_EXCEEDED]";
260
258
  }
261
259
 
262
260
  for (const prop in obj) {
263
- const currentPath = path ? `${path}.${prop}` : prop
264
- const objProp = obj[prop]
261
+ const currentPath = path ? `${path}.${prop}` : prop;
262
+ const objProp = obj[prop];
265
263
 
266
264
  if (isFunction(objProp)) {
267
- stringified[prop] = objProp.toString()
265
+ stringified[prop] = objProp.toString();
268
266
  } else if (isObject(objProp)) {
269
- stringified[prop] = {}
267
+ stringified[prop] = {};
270
268
  deepStringifyWithMaxDepth(
271
269
  objProp,
272
270
  stringified[prop],
273
271
  depth + 1,
274
272
  currentPath
275
- )
273
+ );
276
274
  } else if (isArray(objProp)) {
277
- stringified[prop] = []
275
+ stringified[prop] = [];
278
276
  objProp.forEach((v, i) => {
279
- const itemPath = `${currentPath}[${i}]`
277
+ const itemPath = `${currentPath}[${i}]`;
280
278
  if (isObject(v)) {
281
- stringified[prop][i] = {}
279
+ stringified[prop][i] = {};
282
280
  deepStringifyWithMaxDepth(
283
281
  v,
284
282
  stringified[prop][i],
285
283
  depth + 1,
286
284
  itemPath
287
- )
285
+ );
288
286
  } else if (isFunction(v)) {
289
- stringified[prop][i] = v.toString()
287
+ stringified[prop][i] = v.toString();
290
288
  } else {
291
- stringified[prop][i] = v
289
+ stringified[prop][i] = v;
292
290
  }
293
- })
291
+ });
294
292
  } else {
295
- stringified[prop] = objProp
293
+ stringified[prop] = objProp;
296
294
  }
297
295
  }
298
- return stringified
299
- }
296
+ return stringified;
297
+ };
300
298
 
301
299
  export const objectToString = (obj = {}, indent = 0) => {
302
300
  // Handle empty object case
303
- if (obj === null || typeof obj !== 'object') {
304
- return String(obj)
301
+ if (obj === null || typeof obj !== "object") {
302
+ return String(obj);
305
303
  }
306
304
 
307
305
  // Handle empty object case
308
306
  if (Object.keys(obj).length === 0) {
309
- return '{}'
307
+ return "{}";
310
308
  }
311
309
 
312
- const spaces = ' '.repeat(indent)
313
- let str = '{\n'
310
+ const spaces = " ".repeat(indent);
311
+ let str = "{\n";
314
312
 
315
313
  for (const [key, value] of Object.entries(obj)) {
316
314
  const keyNotAllowdChars = stringIncludesAny(key, [
317
- '&',
318
- '*',
319
- '-',
320
- ':',
321
- '%',
322
- '{',
323
- '}',
324
- '>',
325
- '<',
326
- '@',
327
- '.',
328
- '/',
329
- '!',
330
- ' '
331
- ])
332
- const stringedKey = keyNotAllowdChars ? `'${key}'` : key
333
- str += `${spaces} ${stringedKey}: `
315
+ "&",
316
+ "*",
317
+ "-",
318
+ ":",
319
+ "%",
320
+ "{",
321
+ "}",
322
+ ">",
323
+ "<",
324
+ "@",
325
+ ".",
326
+ "/",
327
+ "!",
328
+ " ",
329
+ ]);
330
+ const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
331
+ str += `${spaces} ${stringedKey}: `;
334
332
 
335
333
  if (isArray(value)) {
336
- str += '[\n'
334
+ str += "[\n";
337
335
  for (const element of value) {
338
336
  if (isObjectLike(element) && element !== null) {
339
- str += `${spaces} ${objectToString(element, indent + 2)},\n`
337
+ str += `${spaces} ${objectToString(element, indent + 2)},\n`;
340
338
  } else if (isString(element)) {
341
- str += `${spaces} '${element}',\n`
339
+ str += `${spaces} '${element}',\n`;
342
340
  } else {
343
- str += `${spaces} ${element},\n`
341
+ str += `${spaces} ${element},\n`;
344
342
  }
345
343
  }
346
- str += `${spaces} ]`
344
+ str += `${spaces} ]`;
347
345
  } else if (isObjectLike(value)) {
348
- str += objectToString(value, indent + 1)
346
+ str += objectToString(value, indent + 1);
349
347
  } else if (isString(value)) {
350
- str += stringIncludesAny(value, ['\n', "'"])
348
+ str += stringIncludesAny(value, ["\n", "'"])
351
349
  ? `\`${value}\``
352
- : `'${value}'`
350
+ : `'${value}'`;
353
351
  } else {
354
- str += value
352
+ str += value;
355
353
  }
356
354
 
357
- str += ',\n'
355
+ str += ",\n";
358
356
  }
359
357
 
360
- str += `${spaces}}`
361
- return str
362
- }
358
+ str += `${spaces}}`;
359
+ return str;
360
+ };
363
361
 
364
362
  /**
365
363
  * Stringify object
366
364
  */
367
365
  export const detachFunctionsFromObject = (obj, detached = {}) => {
368
366
  for (const prop in obj) {
369
- const objProp = obj[prop]
370
- if (isFunction(objProp)) continue
367
+ const objProp = obj[prop];
368
+ if (isFunction(objProp)) continue;
371
369
  else if (isObject(objProp)) {
372
- detached[prop] = {}
373
- deepStringify(objProp, detached[prop])
370
+ detached[prop] = {};
371
+ deepStringify(objProp, detached[prop]);
374
372
  } else if (isArray(objProp)) {
375
- detached[prop] = []
373
+ detached[prop] = [];
376
374
  objProp.forEach((v, i) => {
377
- if (isFunction(v)) return
375
+ if (isFunction(v)) return;
378
376
  if (isObject(v)) {
379
- detached[prop][i] = {}
380
- detachFunctionsFromObject(v, detached[prop][i])
377
+ detached[prop][i] = {};
378
+ detachFunctionsFromObject(v, detached[prop][i]);
381
379
  } else {
382
- detached[prop][i] = v
380
+ detached[prop][i] = v;
383
381
  }
384
- })
382
+ });
385
383
  } else {
386
- detached[prop] = objProp
384
+ detached[prop] = objProp;
387
385
  }
388
386
  }
389
- return detached
390
- }
387
+ return detached;
388
+ };
391
389
 
392
- export const hasFunction = str => {
393
- if (!str) return false
390
+ export const hasFunction = (str) => {
391
+ if (!str) return false;
394
392
 
395
- const trimmed = str.trim().replace(/\n\s*/g, ' ').trim()
393
+ const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
396
394
 
397
- if (trimmed === '') return false
398
- if (trimmed === '{}') return false
399
- if (trimmed === '[]') return false
395
+ if (trimmed === "") return false;
396
+ if (trimmed === "{}") return false;
397
+ if (trimmed === "[]") return false;
400
398
 
401
399
  const patterns = [
402
400
  /^\(\s*\{[^}]*\}\s*\)\s*=>/,
@@ -404,206 +402,211 @@ export const hasFunction = str => {
404
402
  /^function[\s(]/,
405
403
  /^async\s+/,
406
404
  /^\(\s*function/,
407
- /^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
408
- ]
409
-
410
- const isClass = str.startsWith('class')
411
- const isFunction = patterns.some(pattern => pattern.test(trimmed))
412
- const isObjectLiteral = trimmed.startsWith('{') && !trimmed.includes('=>')
413
- const isArrayLiteral = trimmed.startsWith('[')
414
- const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes('=>')
415
-
416
- return (isFunction || isClass) && !isObjectLiteral && !isArrayLiteral && !isJSONLike
417
- }
405
+ /^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/,
406
+ ];
407
+
408
+ const isClass = str.startsWith("class");
409
+ const isFunction = patterns.some((pattern) => pattern.test(trimmed));
410
+ const isObjectLiteral = trimmed.startsWith("{") && !trimmed.includes("=>");
411
+ const isArrayLiteral = trimmed.startsWith("[");
412
+ const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes("=>");
413
+
414
+ return (
415
+ (isFunction || isClass) &&
416
+ !isObjectLiteral &&
417
+ !isArrayLiteral &&
418
+ !isJSONLike
419
+ );
420
+ };
418
421
 
419
422
  export const deepDestringify = (obj, destringified = {}) => {
420
423
  for (const prop in obj) {
421
- const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop)
422
- if (!hasOwnProperty) continue
424
+ const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop);
425
+ if (!hasOwnProperty) continue;
423
426
 
424
- const objProp = obj[prop]
427
+ const objProp = obj[prop];
425
428
 
426
429
  if (isString(objProp)) {
427
430
  if (hasFunction(objProp)) {
428
431
  try {
429
- const evalProp = window.eval(`(${objProp})`)
430
- destringified[prop] = evalProp
432
+ const evalProp = window.eval(`(${objProp})`);
433
+ destringified[prop] = evalProp;
431
434
  } catch (e) {
432
- if (e) destringified[prop] = objProp
435
+ if (e) destringified[prop] = objProp;
433
436
  }
434
437
  } else {
435
- destringified[prop] = objProp
438
+ destringified[prop] = objProp;
436
439
  }
437
440
  } else if (isArray(objProp)) {
438
- destringified[prop] = []
439
- objProp.forEach(arrProp => {
441
+ destringified[prop] = [];
442
+ objProp.forEach((arrProp) => {
440
443
  if (isString(arrProp)) {
441
444
  if (hasFunction(arrProp)) {
442
445
  try {
443
- const evalProp = window.eval(`(${arrProp})`)
444
- destringified[prop].push(evalProp)
446
+ const evalProp = window.eval(`(${arrProp})`);
447
+ destringified[prop].push(evalProp);
445
448
  } catch (e) {
446
- if (e) destringified[prop].push(arrProp)
449
+ if (e) destringified[prop].push(arrProp);
447
450
  }
448
451
  } else {
449
- destringified[prop].push(arrProp)
452
+ destringified[prop].push(arrProp);
450
453
  }
451
454
  } else if (isObject(arrProp)) {
452
- destringified[prop].push(deepDestringify(arrProp))
455
+ destringified[prop].push(deepDestringify(arrProp));
453
456
  } else {
454
- destringified[prop].push(arrProp)
457
+ destringified[prop].push(arrProp);
455
458
  }
456
- })
459
+ });
457
460
  } else if (isObject(objProp)) {
458
- destringified[prop] = deepDestringify(objProp, destringified[prop])
461
+ destringified[prop] = deepDestringify(objProp, destringified[prop]);
459
462
  } else {
460
- destringified[prop] = objProp
463
+ destringified[prop] = objProp;
461
464
  }
462
465
  }
463
- return destringified
464
- }
466
+ return destringified;
467
+ };
465
468
 
466
469
  export const stringToObject = (str, opts = { verbose: true }) => {
467
470
  try {
468
- return str ? window.eval('(' + str + ')') : {} // eslint-disable-line
471
+ return str ? window.eval("(" + str + ")") : {}; // eslint-disable-line
469
472
  } catch (e) {
470
- if (opts.verbose) console.warn(e)
471
- if (opts.errorCallback) opts.errorCallback(e)
473
+ if (opts.verbose) console.warn(e);
474
+ if (opts.errorCallback) opts.errorCallback(e);
472
475
  }
473
- }
476
+ };
474
477
 
475
478
  export const diffObjects = (original, objToDiff, cache) => {
476
479
  for (const e in objToDiff) {
477
- if (e === 'ref') continue
480
+ if (e === "ref") continue;
478
481
 
479
- const originalProp = original[e]
480
- const objToDiffProp = objToDiff[e]
482
+ const originalProp = original[e];
483
+ const objToDiffProp = objToDiff[e];
481
484
 
482
485
  if (isObject(originalProp) && isObject(objToDiffProp)) {
483
- cache[e] = {}
484
- diff(originalProp, objToDiffProp, cache[e])
486
+ cache[e] = {};
487
+ diff(originalProp, objToDiffProp, cache[e]);
485
488
  } else if (objToDiffProp !== undefined) {
486
- cache[e] = objToDiffProp
489
+ cache[e] = objToDiffProp;
487
490
  }
488
491
  }
489
- return cache
490
- }
492
+ return cache;
493
+ };
491
494
 
492
495
  export const diffArrays = (original, objToDiff, cache) => {
493
496
  if (original.length !== objToDiff.length) {
494
- cache = objToDiff
497
+ cache = objToDiff;
495
498
  } else {
496
- const diffArr = []
499
+ const diffArr = [];
497
500
  for (let i = 0; i < original.length; i++) {
498
- const diffObj = diff(original[i], objToDiff[i])
501
+ const diffObj = diff(original[i], objToDiff[i]);
499
502
  if (Object.keys(diffObj).length > 0) {
500
- diffArr.push(diffObj)
503
+ diffArr.push(diffObj);
501
504
  }
502
505
  }
503
506
  if (diffArr.length > 0) {
504
- cache = diffArr
507
+ cache = diffArr;
505
508
  }
506
509
  }
507
- return cache
508
- }
510
+ return cache;
511
+ };
509
512
 
510
513
  export const diff = (original, objToDiff, cache = {}) => {
511
514
  if (isArray(original) && isArray(objToDiff)) {
512
- cache = []
513
- diffArrays(original, objToDiff, cache)
515
+ cache = [];
516
+ diffArrays(original, objToDiff, cache);
514
517
  } else {
515
- diffObjects(original, objToDiff, cache)
518
+ diffObjects(original, objToDiff, cache);
516
519
  }
517
520
 
518
- return cache
519
- }
521
+ return cache;
522
+ };
520
523
 
521
524
  export const hasOwnProperty = (o, ...args) =>
522
- Object.prototype.hasOwnProperty.call(o, ...args)
525
+ Object.prototype.hasOwnProperty.call(o, ...args);
523
526
 
524
- export const isEmpty = o => Object.keys(o).length === 0
527
+ export const isEmpty = (o) => Object.keys(o).length === 0;
525
528
 
526
- export const isEmptyObject = o => isObject(o) && isEmpty(o)
529
+ export const isEmptyObject = (o) => isObject(o) && isEmpty(o);
527
530
 
528
- export const makeObjectWithoutPrototype = () => Object.create(null)
531
+ export const makeObjectWithoutPrototype = () => Object.create(null);
529
532
 
530
533
  // by mattphillips
531
534
  // https://github.com/mattphillips/deep-object-diff/blob/main/src/diff.js
532
535
  export const deepDiff = (lhs, rhs) => {
533
- if (lhs === rhs) return {}
536
+ if (lhs === rhs) return {};
534
537
 
535
- if (!isObjectLike(lhs) || !isObjectLike(rhs)) return rhs
538
+ if (!isObjectLike(lhs) || !isObjectLike(rhs)) return rhs;
536
539
 
537
540
  const deletedValues = Object.keys(lhs).reduce((acc, key) => {
538
541
  if (!hasOwnProperty(rhs, key)) {
539
- acc[key] = undefined
542
+ acc[key] = undefined;
540
543
  }
541
544
 
542
- return acc
543
- }, makeObjectWithoutPrototype())
545
+ return acc;
546
+ }, makeObjectWithoutPrototype());
544
547
 
545
548
  if (isDate(lhs) || isDate(rhs)) {
546
- if (lhs.valueOf() === rhs.valueOf()) return {}
547
- return rhs
549
+ if (lhs.valueOf() === rhs.valueOf()) return {};
550
+ return rhs;
548
551
  }
549
552
 
550
553
  return Object.keys(rhs).reduce((acc, key) => {
551
554
  if (!hasOwnProperty(lhs, key)) {
552
- acc[key] = rhs[key]
553
- return acc
555
+ acc[key] = rhs[key];
556
+ return acc;
554
557
  }
555
558
 
556
- const difference = diff(lhs[key], rhs[key])
559
+ const difference = diff(lhs[key], rhs[key]);
557
560
 
558
561
  if (
559
562
  isEmptyObject(difference) &&
560
563
  !isDate(difference) &&
561
564
  (isEmptyObject(lhs[key]) || !isEmptyObject(rhs[key]))
562
565
  ) {
563
- return acc
566
+ return acc;
564
567
  }
565
568
 
566
- acc[key] = difference
567
- return acc
568
- }, deletedValues)
569
- }
569
+ acc[key] = difference;
570
+ return acc;
571
+ }, deletedValues);
572
+ };
570
573
 
571
574
  /**
572
575
  * Overwrites object properties with another
573
576
  */
574
577
  export const overwrite = (element, params, opts = {}) => {
575
- const { __ref: ref } = element
576
- const excl = opts.exclude || []
577
- const allowUnderscore = opts.preventUnderscore
578
- const preventCaching = opts.preventCaching
578
+ const { __ref: ref } = element;
579
+ const excl = opts.exclude || [];
580
+ const allowUnderscore = opts.preventUnderscore;
581
+ const preventCaching = opts.preventCaching;
579
582
 
580
583
  for (const e in params) {
581
- if (excl.includes(e) || (!allowUnderscore && e.startsWith('__'))) continue
584
+ if (excl.includes(e) || (!allowUnderscore && e.startsWith("__"))) continue;
582
585
 
583
- const elementProp = element[e]
584
- const paramsProp = params[e]
586
+ const elementProp = element[e];
587
+ const paramsProp = params[e];
585
588
 
586
589
  if (paramsProp !== undefined) {
587
- element[e] = paramsProp
590
+ element[e] = paramsProp;
588
591
  if (ref && !preventCaching) {
589
- ref.__cache[e] = elementProp
592
+ ref.__cache[e] = elementProp;
590
593
  }
591
594
  if (isObject(opts.diff)) {
592
- diff[e] = elementProp
595
+ diff[e] = elementProp;
593
596
  }
594
597
  }
595
598
  }
596
599
 
597
- return element
598
- }
600
+ return element;
601
+ };
599
602
 
600
603
  export const overwriteShallow = (obj, params, excludeFrom = []) => {
601
604
  for (const e in params) {
602
- if (excludeFrom.includes(e) || e.startsWith('__')) continue
603
- obj[e] = params[e]
605
+ if (excludeFrom.includes(e) || e.startsWith("__")) continue;
606
+ obj[e] = params[e];
604
607
  }
605
- return obj
606
- }
608
+ return obj;
609
+ };
607
610
 
608
611
  /**
609
612
  * Overwrites DEEPLY object properties with another
@@ -614,8 +617,8 @@ export const overwriteDeep = (
614
617
  opts = {},
615
618
  visited = new WeakMap()
616
619
  ) => {
617
- const excl = opts.exclude || []
618
- const forcedExclude = opts.preventForce ? [] : ['node', 'window']
620
+ const excl = opts.exclude || [];
621
+ const forcedExclude = opts.preventForce ? [] : ["node", "window"];
619
622
 
620
623
  if (
621
624
  !isObjectLike(obj) ||
@@ -623,53 +626,53 @@ export const overwriteDeep = (
623
626
  isDOMNode(obj) ||
624
627
  isDOMNode(params)
625
628
  ) {
626
- return params
629
+ return params;
627
630
  }
628
631
 
629
- if (visited.has(obj)) return visited.get(obj)
630
- visited.set(obj, obj)
632
+ if (visited.has(obj)) return visited.get(obj);
633
+ visited.set(obj, obj);
631
634
 
632
635
  for (const e in params) {
633
- if (!Object.hasOwnProperty.call(params, e)) continue
634
- if (excl.includes(e) || (forcedExclude && e.startsWith('__'))) continue
636
+ if (!Object.hasOwnProperty.call(params, e)) continue;
637
+ if (excl.includes(e) || (forcedExclude && e.startsWith("__"))) continue;
635
638
 
636
- const objProp = obj[e]
637
- const paramsProp = params[e]
639
+ const objProp = obj[e];
640
+ const paramsProp = params[e];
638
641
 
639
642
  if (isDOMNode(paramsProp)) {
640
- obj[e] = paramsProp
643
+ obj[e] = paramsProp;
641
644
  } else if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
642
- obj[e] = overwriteDeep(objProp, paramsProp, opts, visited)
645
+ obj[e] = overwriteDeep(objProp, paramsProp, opts, visited);
643
646
  } else if (paramsProp !== undefined) {
644
- obj[e] = paramsProp
647
+ obj[e] = paramsProp;
645
648
  }
646
649
  }
647
650
 
648
- return obj
649
- }
651
+ return obj;
652
+ };
650
653
 
651
654
  /**
652
655
  * Overwrites object properties with another
653
656
  */
654
657
  export const mergeIfExisted = (a, b) => {
655
- if (isObjectLike(a) && isObjectLike(b)) return deepMerge(a, b)
656
- return a || b
657
- }
658
+ if (isObjectLike(a) && isObjectLike(b)) return deepMerge(a, b);
659
+ return a || b;
660
+ };
658
661
 
659
662
  /**
660
663
  * Overwrites object properties with another
661
664
  */
662
665
  export const flattenRecursive = (param, prop, stack = []) => {
663
- const objectized = mergeAndCloneIfArray(param)
664
- stack.push(objectized)
666
+ const objectized = mergeAndCloneIfArray(param);
667
+ stack.push(objectized);
665
668
 
666
- const extendOfExtend = objectized[prop]
667
- if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack)
669
+ const extendOfExtend = objectized[prop];
670
+ if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack);
668
671
 
669
- delete objectized[prop]
672
+ delete objectized[prop];
670
673
 
671
- return stack
672
- }
674
+ return stack;
675
+ };
673
676
 
674
677
  /**
675
678
  * Recursively compares two values to determine if they are deeply equal.
@@ -708,257 +711,257 @@ export const flattenRecursive = (param, prop, stack = []) => {
708
711
  export const isEqualDeep = (param, element, visited = new Set()) => {
709
712
  // Check if both values are non-null objects
710
713
  if (
711
- typeof param !== 'object' ||
712
- typeof element !== 'object' ||
714
+ typeof param !== "object" ||
715
+ typeof element !== "object" ||
713
716
  param === null ||
714
717
  element === null
715
718
  ) {
716
- return param === element // Compare non-object values directly
719
+ return param === element; // Compare non-object values directly
717
720
  }
718
721
 
719
722
  // Check for circular references
720
723
  if (visited.has(param) || visited.has(element)) {
721
- return true // Assume equality to break the circular reference
724
+ return true; // Assume equality to break the circular reference
722
725
  }
723
726
 
724
- visited.add(param)
725
- visited.add(element)
727
+ visited.add(param);
728
+ visited.add(element);
726
729
 
727
- const keysParam = Object.keys(param)
728
- const keysElement = Object.keys(element)
730
+ const keysParam = Object.keys(param);
731
+ const keysElement = Object.keys(element);
729
732
 
730
733
  // Check if both objects have the same number of properties
731
734
  if (keysParam.length !== keysElement.length) {
732
- return false
735
+ return false;
733
736
  }
734
737
 
735
738
  // Check if all properties in param also exist in element
736
739
  for (const key of keysParam) {
737
740
  if (!keysElement.includes(key)) {
738
- return false
741
+ return false;
739
742
  }
740
743
 
741
- const paramProp = param[key]
742
- const elementProp = element[key]
744
+ const paramProp = param[key];
745
+ const elementProp = element[key];
743
746
 
744
747
  // Recursively check property values
745
748
  if (!isEqualDeep(paramProp, elementProp, visited)) {
746
- return false
749
+ return false;
747
750
  }
748
751
  }
749
752
 
750
- return true
751
- }
753
+ return true;
754
+ };
752
755
 
753
- export const deepContains = (obj1, obj2, ignoredKeys = ['node', '__ref']) => {
754
- if (obj1 === obj2) return true
755
- if (!isObjectLike(obj1) || !isObjectLike(obj2)) return false
756
- if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2
756
+ export const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
757
+ if (obj1 === obj2) return true;
758
+ if (!isObjectLike(obj1) || !isObjectLike(obj2)) return false;
759
+ if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2;
757
760
 
758
- const stack = [[obj1, obj2]]
759
- const visited = new WeakSet()
761
+ const stack = [[obj1, obj2]];
762
+ const visited = new WeakSet();
760
763
 
761
764
  while (stack.length > 0) {
762
- const [current1, current2] = stack.pop()
765
+ const [current1, current2] = stack.pop();
763
766
 
764
- if (visited.has(current1)) continue
765
- visited.add(current1)
767
+ if (visited.has(current1)) continue;
768
+ visited.add(current1);
766
769
 
767
770
  const keys1 = Object.keys(current1).filter(
768
- key => !ignoredKeys.includes(key)
769
- )
771
+ (key) => !ignoredKeys.includes(key)
772
+ );
770
773
  const keys2 = Object.keys(current2).filter(
771
- key => !ignoredKeys.includes(key)
772
- )
774
+ (key) => !ignoredKeys.includes(key)
775
+ );
773
776
 
774
- if (keys1.length !== keys2.length) return false
777
+ if (keys1.length !== keys2.length) return false;
775
778
 
776
779
  for (const key of keys1) {
777
- if (!Object.prototype.hasOwnProperty.call(current2, key)) return false
780
+ if (!Object.prototype.hasOwnProperty.call(current2, key)) return false;
778
781
 
779
- const value1 = current1[key]
780
- const value2 = current2[key]
782
+ const value1 = current1[key];
783
+ const value2 = current2[key];
781
784
 
782
785
  if (isDOMNode(value1) || isDOMNode(value2)) {
783
- if (value1 !== value2) return false
786
+ if (value1 !== value2) return false;
784
787
  } else if (isObjectLike(value1) && isObjectLike(value2)) {
785
788
  if (value1 !== value2) {
786
- stack.push([value1, value2])
789
+ stack.push([value1, value2]);
787
790
  }
788
791
  } else if (value1 !== value2) {
789
- return false
792
+ return false;
790
793
  }
791
794
  }
792
795
  }
793
796
 
794
- return true
795
- }
797
+ return true;
798
+ };
796
799
 
797
800
  export const removeFromObject = (obj, props) => {
798
- if (props === undefined || props === null) return obj
799
- if (is(props)('string', 'number')) {
800
- delete obj[props]
801
+ if (props === undefined || props === null) return obj;
802
+ if (is(props)("string", "number")) {
803
+ delete obj[props];
801
804
  } else if (isArray(props)) {
802
- props.forEach(prop => delete obj[prop])
805
+ props.forEach((prop) => delete obj[prop]);
803
806
  } else {
804
807
  throw new Error(
805
- 'Invalid input: props must be a string or an array of strings'
806
- )
808
+ "Invalid input: props must be a string or an array of strings"
809
+ );
807
810
  }
808
- return obj
809
- }
811
+ return obj;
812
+ };
810
813
 
811
- export const createObjectWithoutPrototype = obj => {
812
- if (obj === null || typeof obj !== 'object') {
813
- return obj // Return the value if obj is not an object
814
+ export const createObjectWithoutPrototype = (obj) => {
815
+ if (obj === null || typeof obj !== "object") {
816
+ return obj; // Return the value if obj is not an object
814
817
  }
815
818
 
816
- const newObj = Object.create(null) // Create an object without prototype
819
+ const newObj = Object.create(null); // Create an object without prototype
817
820
 
818
821
  for (const key in obj) {
819
822
  if (Object.prototype.hasOwnProperty.call(obj, key)) {
820
- newObj[key] = createObjectWithoutPrototype(obj[key]) // Recursively copy each property
823
+ newObj[key] = createObjectWithoutPrototype(obj[key]); // Recursively copy each property
821
824
  }
822
825
  }
823
826
 
824
- return newObj
825
- }
827
+ return newObj;
828
+ };
826
829
 
827
830
  export const createNestedObject = (arr, lastValue) => {
828
- const nestedObject = {}
831
+ const nestedObject = {};
829
832
 
830
833
  if (arr.length === 0) {
831
- return lastValue
834
+ return lastValue;
832
835
  }
833
836
 
834
837
  arr.reduce((obj, value, index) => {
835
838
  if (!obj[value]) {
836
- obj[value] = {}
839
+ obj[value] = {};
837
840
  }
838
841
  if (index === arr.length - 1 && lastValue !== undefined) {
839
- obj[value] = lastValue
842
+ obj[value] = lastValue;
840
843
  }
841
- return obj[value]
842
- }, nestedObject)
844
+ return obj[value];
845
+ }, nestedObject);
843
846
 
844
- return nestedObject
845
- }
847
+ return nestedObject;
848
+ };
846
849
 
847
850
  export const removeNestedKeyByPath = (obj, path) => {
848
851
  if (!Array.isArray(path)) {
849
- throw new Error('Path must be an array.')
852
+ throw new Error("Path must be an array.");
850
853
  }
851
854
 
852
- let current = obj
855
+ let current = obj;
853
856
 
854
857
  for (let i = 0; i < path.length - 1; i++) {
855
858
  if (current[path[i]] === undefined) {
856
- return // Path does not exist, so nothing to remove.
859
+ return; // Path does not exist, so nothing to remove.
857
860
  }
858
- current = current[path[i]]
861
+ current = current[path[i]];
859
862
  }
860
863
 
861
- const lastKey = path[path.length - 1]
864
+ const lastKey = path[path.length - 1];
862
865
  if (current && Object.hasOwnProperty.call(current, lastKey)) {
863
- delete current[lastKey]
866
+ delete current[lastKey];
864
867
  }
865
- }
868
+ };
866
869
 
867
870
  export const setInObjectByPath = (obj, path, value) => {
868
871
  if (!Array.isArray(path)) {
869
- throw new Error('Path must be an array.')
872
+ throw new Error("Path must be an array.");
870
873
  }
871
874
 
872
- let current = obj
875
+ let current = obj;
873
876
 
874
877
  for (let i = 0; i < path.length - 1; i++) {
875
878
  // If the current path segment doesn't exist or isn't an object, create it
876
- if (!current[path[i]] || typeof current[path[i]] !== 'object') {
877
- current[path[i]] = {}
879
+ if (!current[path[i]] || typeof current[path[i]] !== "object") {
880
+ current[path[i]] = {};
878
881
  }
879
- current = current[path[i]]
882
+ current = current[path[i]];
880
883
  }
881
884
 
882
- const lastKey = path[path.length - 1]
883
- current[lastKey] = value
885
+ const lastKey = path[path.length - 1];
886
+ current[lastKey] = value;
884
887
 
885
- return obj
886
- }
888
+ return obj;
889
+ };
887
890
 
888
891
  export const getInObjectByPath = (obj, path) => {
889
892
  if (!Array.isArray(path)) {
890
- throw new Error('Path must be an array.')
893
+ throw new Error("Path must be an array.");
891
894
  }
892
895
 
893
- let current = obj
896
+ let current = obj;
894
897
 
895
898
  for (let i = 0; i < path.length; i++) {
896
899
  if (current === undefined || current === null) {
897
- return undefined
900
+ return undefined;
898
901
  }
899
- current = current[path[i]]
902
+ current = current[path[i]];
900
903
  }
901
904
 
902
- return current
903
- }
905
+ return current;
906
+ };
904
907
 
905
- export const detectInfiniteLoop = arr => {
906
- const maxRepeats = 10 // Maximum allowed repetitions
907
- let pattern = []
908
- let repeatCount = 0
908
+ export const detectInfiniteLoop = (arr) => {
909
+ const maxRepeats = 10; // Maximum allowed repetitions
910
+ let pattern = [];
911
+ let repeatCount = 0;
909
912
 
910
913
  for (let i = 0; i < arr.length; i++) {
911
914
  if (pattern.length < 2) {
912
915
  // Build the initial pattern with two consecutive elements
913
- pattern.push(arr[i])
916
+ pattern.push(arr[i]);
914
917
  } else {
915
918
  // Check if the current element follows the repeating pattern
916
919
  if (arr[i] === pattern[i % 2]) {
917
- repeatCount++
920
+ repeatCount++;
918
921
  } else {
919
922
  // If there's a mismatch, reset the pattern and repeat counter
920
- pattern = [arr[i - 1], arr[i]]
921
- repeatCount = 1 // Reset to 1 because we start a new potential pattern
923
+ pattern = [arr[i - 1], arr[i]];
924
+ repeatCount = 1; // Reset to 1 because we start a new potential pattern
922
925
  }
923
926
 
924
927
  // If the pattern repeats more than `maxRepeats`, throw a warning
925
928
  if (repeatCount >= maxRepeats * 2) {
926
929
  if (isNotProduction()) {
927
930
  console.warn(
928
- 'Warning: Potential infinite loop detected due to repeated sequence:',
931
+ "Warning: Potential infinite loop detected due to repeated sequence:",
929
932
  pattern
930
- )
933
+ );
931
934
  }
932
- return true
935
+ return true;
933
936
  }
934
937
  }
935
938
  }
936
- }
939
+ };
937
940
 
938
- export const isCyclic = obj => {
939
- const seenObjects = []
941
+ export const isCyclic = (obj) => {
942
+ const seenObjects = [];
940
943
 
941
- function detect (obj) {
942
- if (obj && typeof obj === 'object') {
944
+ function detect(obj) {
945
+ if (obj && typeof obj === "object") {
943
946
  if (seenObjects.indexOf(obj) !== -1) {
944
- return true
947
+ return true;
945
948
  }
946
- seenObjects.push(obj)
949
+ seenObjects.push(obj);
947
950
  for (const key in obj) {
948
951
  if (Object.hasOwnProperty.call(obj, key) && detect(obj[key])) {
949
- console.log(obj, 'cycle at ' + key)
950
- return true
952
+ console.log(obj, "cycle at " + key);
953
+ return true;
951
954
  }
952
955
  }
953
956
  }
954
- return false
957
+ return false;
955
958
  }
956
959
 
957
- return detect(obj)
958
- }
960
+ return detect(obj);
961
+ };
959
962
 
960
963
  export const excludeKeysFromObject = (obj, excludedKeys) => {
961
- const result = { ...obj }
962
- excludedKeys.forEach(key => delete result[key])
963
- return result
964
- }
964
+ const result = { ...obj };
965
+ excludedKeys.forEach((key) => delete result[key]);
966
+ return result;
967
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.29.51",
3
+ "version": "2.29.53",
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": "afbffe9a2317d2d0929447ab49251d83296bf546",
27
+ "gitHead": "87f9120f580203116585f21335aa97cc7dbfde6d",
28
28
  "devDependencies": {
29
29
  "@babel/core": "^7.27.1"
30
30
  }