@domql/utils 2.5.185 → 2.5.200

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/dist/cjs/array.js CHANGED
@@ -48,8 +48,7 @@ const getFrequencyInArray = (arr, value) => {
48
48
  }, 0);
49
49
  };
50
50
  const removeFromArray = (arr, index) => {
51
- if ((0, import_types.isString)(index))
52
- index = parseInt(index);
51
+ if ((0, import_types.isString)(index)) index = parseInt(index);
53
52
  if ((0, import_types.isNumber)(index)) {
54
53
  if (index < 0 || index >= arr.length || isNaN(index)) {
55
54
  throw new Error("Invalid index");
@@ -82,8 +81,7 @@ const cutArrayBeforeValue = (arr, value) => {
82
81
  return arr;
83
82
  };
84
83
  const cutArrayAfterValue = (arr, value) => {
85
- if (!(0, import_types.isArray)(arr))
86
- return;
84
+ if (!(0, import_types.isArray)(arr)) return;
87
85
  const index = arr.indexOf(value);
88
86
  if (index !== -1) {
89
87
  return arr.slice(index + 1);
@@ -142,7 +140,6 @@ const filterArraysFast = (sourceArr, excludeArr) => {
142
140
  return sourceArr.filter((item) => !excludeSet.has(item));
143
141
  };
144
142
  const checkIfStringIsInArray = (string, arr) => {
145
- if (!string)
146
- return;
143
+ if (!string) return;
147
144
  return arr.filter((v) => string.includes(v)).length;
148
145
  };
@@ -41,21 +41,18 @@ var import_types = require("./types.js");
41
41
  const ENV = "development";
42
42
  const checkIfKeyIsComponent = (key) => {
43
43
  const isFirstKeyString = (0, import_types.isString)(key);
44
- if (!isFirstKeyString)
45
- return;
44
+ if (!isFirstKeyString) return;
46
45
  const firstCharKey = key.slice(0, 1);
47
46
  return /^[A-Z]*$/.test(firstCharKey);
48
47
  };
49
48
  const checkIfKeyIsProperty = (key) => {
50
49
  const isFirstKeyString = (0, import_types.isString)(key);
51
- if (!isFirstKeyString)
52
- return;
50
+ if (!isFirstKeyString) return;
53
51
  const firstCharKey = key.slice(0, 1);
54
52
  return /^[a-z]*$/.test(firstCharKey);
55
53
  };
56
54
  const addAdditionalExtend = (newExtend, element) => {
57
- if (!newExtend)
58
- return element;
55
+ if (!newExtend) return element;
59
56
  const { extend: elementExtend } = element;
60
57
  const originalArray = (0, import_types.isArray)(elementExtend) ? elementExtend : [elementExtend];
61
58
  const receivedArray = (0, import_types.isArray)(newExtend) ? newExtend : [newExtend];
@@ -80,8 +77,7 @@ const checkIfSugar = (element, parent, key) => {
80
77
  const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
81
78
  if (hasComponentAttrs && (childProps || extendProps || children || childExtends)) {
82
79
  const logErr = (_a = parent || element) == null ? void 0 : _a.error;
83
- if (logErr)
84
- logErr.call(element, "Sugar component includes params for builtin components", { verbose: true });
80
+ if (logErr) logErr.call(element, "Sugar component includes params for builtin components", { verbose: true });
85
81
  }
86
82
  return !hasComponentAttrs || childProps || extendProps || children || childExtends;
87
83
  };
@@ -94,8 +90,7 @@ const extendizeByKey = (element, parent, key) => {
94
90
  const isSugar = checkIfSugar(element, parent, key);
95
91
  const extendFromKey = extractComponentKeyFromKey(key);
96
92
  const isExtendKeyComponent = context && context.components[extendFromKey];
97
- if (element === isExtendKeyComponent)
98
- return element;
93
+ if (element === isExtendKeyComponent) return element;
99
94
  else if (isSugar) {
100
95
  const newElem = addAdditionalExtend(element.extends, {
101
96
  extend: extendFromKey,
@@ -118,8 +113,7 @@ const extendizeByKey = (element, parent, key) => {
118
113
  newElem.if = newElem.props.if;
119
114
  delete newElem.props.if;
120
115
  }
121
- if (childExtends)
122
- newElem.childExtend = childExtends;
116
+ if (childExtends) newElem.childExtend = childExtends;
123
117
  return newElem;
124
118
  } else if (!extend || extend === true) {
125
119
  return {
@@ -142,8 +136,7 @@ function getCapitalCaseKeys(obj) {
142
136
  }
143
137
  const addChildrenIfNotInOriginal = (element, parent, key) => {
144
138
  const childElems = getCapitalCaseKeys(element.props);
145
- if (!childElems.length)
146
- return element;
139
+ if (!childElems.length) return element;
147
140
  for (const i in childElems) {
148
141
  const childKey = childElems[i];
149
142
  const childElem = element[childKey];
@@ -152,16 +145,12 @@ const addChildrenIfNotInOriginal = (element, parent, key) => {
152
145
  element[childKey] = val;
153
146
  delete element.props[childKey];
154
147
  };
155
- if (newChild == null ? void 0 : newChild.ignoreExtend)
156
- continue;
157
- if (newChild === null)
158
- assignChild(null);
159
- else if (!childElem)
160
- assignChild((0, import_object.deepClone)(newChild));
148
+ if (newChild == null ? void 0 : newChild.ignoreExtend) continue;
149
+ if (newChild === null) assignChild(null);
150
+ else if (!childElem) assignChild((0, import_object.deepClone)(newChild));
161
151
  else {
162
152
  const isSugarChildElem = checkIfSugar(childElem, parent, key);
163
- if (isSugarChildElem)
164
- continue;
153
+ if (isSugarChildElem) continue;
165
154
  assignChild({
166
155
  extend: element[childKey],
167
156
  props: newChild
@@ -174,15 +163,13 @@ const applyKeyComponentAsExtend = (element, parent, key) => {
174
163
  };
175
164
  const applyComponentFromContext = (element, parent, options) => {
176
165
  const { context } = element;
177
- if (!context || !context.components)
178
- return;
166
+ if (!context || !context.components) return;
179
167
  const { components } = context;
180
168
  const { extend } = element;
181
169
  const execExtend = (0, import_object.exec)(extend, element);
182
170
  if ((0, import_types.isString)(execExtend)) {
183
171
  const componentExists = components[execExtend] || components["smbls." + execExtend];
184
- if (componentExists)
185
- element.extend = componentExists;
172
+ if (componentExists) element.extend = componentExists;
186
173
  else {
187
174
  if ((ENV === "test" || ENV === "development") && options.verbose) {
188
175
  console.warn(execExtend, "is not in library", components, element);
@@ -193,15 +180,13 @@ const applyComponentFromContext = (element, parent, options) => {
193
180
  }
194
181
  };
195
182
  const isVariant = (param) => {
196
- if (!(0, import_types.isString)(param))
197
- return;
183
+ if (!(0, import_types.isString)(param)) return;
198
184
  const firstCharKey = param.slice(0, 1);
199
185
  return firstCharKey === ".";
200
186
  };
201
187
  const hasVariantProp = (element) => {
202
188
  const { props } = element;
203
- if ((0, import_types.isObject)(props) && (0, import_types.isString)(props.variant))
204
- return true;
189
+ if ((0, import_types.isObject)(props) && (0, import_types.isString)(props.variant)) return true;
205
190
  };
206
191
  const getChildrenComponentsByKey = (key, el) => {
207
192
  if (key === el.key || el.__ref.__componentKey === key) {
@@ -210,14 +195,12 @@ const getChildrenComponentsByKey = (key, el) => {
210
195
  if (el.extend) {
211
196
  const foundString = (0, import_types.isString)(el.extend) && el.extend === key;
212
197
  const foundInArray = (0, import_types.isArray)(el.extend) && el.extend.filter((v) => v === key).length;
213
- if (foundString || foundInArray)
214
- return el;
198
+ if (foundString || foundInArray) return el;
215
199
  }
216
200
  if (el.parent && el.parent.childExtend) {
217
201
  const foundString = (0, import_types.isString)(el.parent.childExtend) && el.parent.childExtend === key;
218
202
  const foundInArray = (0, import_types.isArray)(el.parent.childExtend) && el.parent.childExtend.filter((v) => v === key).length;
219
- if (foundString || foundInArray)
220
- return el;
203
+ if (foundString || foundInArray) return el;
221
204
  }
222
205
  };
223
206
  const getExtendsInElement = (obj) => {
@@ -249,9 +232,7 @@ const setContentKey = (el, opts = {}) => {
249
232
  const contentElementKey = opts.contentElementKey;
250
233
  if (contentElementKey !== "content" && contentElementKey !== ref.contentElementKey || !ref.contentElementKey) {
251
234
  ref.contentElementKey = contentElementKey || "content";
252
- } else
253
- ref.contentElementKey = "content";
254
- if (contentElementKey !== "content")
255
- opts.contentElementKey = "content";
235
+ } else ref.contentElementKey = "content";
236
+ if (contentElementKey !== "content") opts.contentElementKey = "content";
256
237
  return ref.contentElementKey;
257
238
  };
@@ -30,31 +30,26 @@ var import_types = require("./types.js");
30
30
  var import_globals = require("./globals.js");
31
31
  const isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))();
32
32
  const setCookie = (cname, cvalue, exdays = 365) => {
33
- if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie))
34
- return;
33
+ if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie)) return;
35
34
  const d = /* @__PURE__ */ new Date();
36
35
  d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1e3);
37
36
  const expires = `expires=${d.toUTCString()}`;
38
37
  import_globals.document.cookie = `${cname}=${cvalue};${expires};path=/`;
39
38
  };
40
39
  const getCookie = (cname) => {
41
- if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie))
42
- return;
40
+ if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie)) return;
43
41
  const name = `${cname}=`;
44
42
  const decodedCookie = decodeURIComponent(import_globals.document.cookie);
45
43
  const ca = decodedCookie.split(";");
46
44
  for (let i = 0; i < ca.length; i++) {
47
45
  let c = ca[i];
48
- while (c.charAt(0) === " ")
49
- c = c.substring(1);
50
- if (c.indexOf(name) === 0)
51
- return c.substring(name.length, c.length);
46
+ while (c.charAt(0) === " ") c = c.substring(1);
47
+ if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
52
48
  }
53
49
  return "";
54
50
  };
55
51
  const removeCookie = (cname) => {
56
- if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie))
57
- return;
52
+ if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie)) return;
58
53
  import_globals.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
59
54
  };
60
55
  function getLocalStorage(key) {
@@ -32,14 +32,12 @@ function debounce(func, wait, immediate) {
32
32
  const args = arguments;
33
33
  const later = function() {
34
34
  timeout = null;
35
- if (!immediate)
36
- func.apply(context, args);
35
+ if (!immediate) func.apply(context, args);
37
36
  };
38
37
  const callNow = immediate && !timeout;
39
38
  clearTimeout(timeout);
40
39
  timeout = setTimeout(later, wait);
41
- if (callNow)
42
- func.apply(context, args);
40
+ if (callNow) func.apply(context, args);
43
41
  };
44
42
  }
45
43
  const debounceOnContext = (element, func, timeout = 300) => {
package/dist/cjs/index.js CHANGED
@@ -13,18 +13,18 @@ var __copyProps = (to, from, except, desc) => {
13
13
  };
14
14
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var utils_exports = {};
17
- module.exports = __toCommonJS(utils_exports);
18
- __reExport(utils_exports, require("./key.js"), module.exports);
19
- __reExport(utils_exports, require("./env.js"), module.exports);
20
- __reExport(utils_exports, require("./types.js"), module.exports);
21
- __reExport(utils_exports, require("./object.js"), module.exports);
22
- __reExport(utils_exports, require("./function.js"), module.exports);
23
- __reExport(utils_exports, require("./array.js"), module.exports);
24
- __reExport(utils_exports, require("./node.js"), module.exports);
25
- __reExport(utils_exports, require("./log.js"), module.exports);
26
- __reExport(utils_exports, require("./string.js"), module.exports);
27
- __reExport(utils_exports, require("./globals.js"), module.exports);
28
- __reExport(utils_exports, require("./cookie.js"), module.exports);
29
- __reExport(utils_exports, require("./tags.js"), module.exports);
30
- __reExport(utils_exports, require("./component.js"), module.exports);
16
+ var index_exports = {};
17
+ module.exports = __toCommonJS(index_exports);
18
+ __reExport(index_exports, require("./key.js"), module.exports);
19
+ __reExport(index_exports, require("./env.js"), module.exports);
20
+ __reExport(index_exports, require("./types.js"), module.exports);
21
+ __reExport(index_exports, require("./object.js"), module.exports);
22
+ __reExport(index_exports, require("./function.js"), module.exports);
23
+ __reExport(index_exports, require("./array.js"), module.exports);
24
+ __reExport(index_exports, require("./node.js"), module.exports);
25
+ __reExport(index_exports, require("./log.js"), module.exports);
26
+ __reExport(index_exports, require("./string.js"), module.exports);
27
+ __reExport(index_exports, require("./globals.js"), module.exports);
28
+ __reExport(index_exports, require("./cookie.js"), module.exports);
29
+ __reExport(index_exports, require("./tags.js"), module.exports);
30
+ __reExport(index_exports, require("./component.js"), module.exports);
package/dist/cjs/key.js CHANGED
@@ -22,7 +22,7 @@ __export(key_exports, {
22
22
  generateKey: () => generateKey
23
23
  });
24
24
  module.exports = __toCommonJS(key_exports);
25
- const generateKey = function() {
25
+ const generateKey = /* @__PURE__ */ function() {
26
26
  let index = 0;
27
27
  function newId() {
28
28
  index++;
package/dist/cjs/log.js CHANGED
@@ -23,8 +23,7 @@ __export(log_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(log_exports);
25
25
  const logIf = (bool, ...arg) => {
26
- if (bool)
27
- arg.map((v) => console.log(v));
26
+ if (bool) arg.map((v) => console.log(v));
28
27
  };
29
28
  const logGroupIf = (bool, key, ...arg) => {
30
29
  if (bool) {
@@ -37,6 +37,7 @@ __export(object_exports, {
37
37
  exec: () => exec,
38
38
  flattenRecursive: () => flattenRecursive,
39
39
  getInObjectByPath: () => getInObjectByPath,
40
+ hasFunction: () => hasFunction,
40
41
  hasOwnProperty: () => hasOwnProperty,
41
42
  isCyclic: () => isCyclic,
42
43
  isEmpty: () => isEmpty,
@@ -82,8 +83,7 @@ const map = (obj, extention, element) => {
82
83
  const merge = (element, obj, excludeFrom = []) => {
83
84
  for (const e in obj) {
84
85
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, e);
85
- if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
86
- continue;
86
+ if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) continue;
87
87
  const elementProp = element[e];
88
88
  const objProp = obj[e];
89
89
  if (elementProp === void 0) {
@@ -95,8 +95,7 @@ const merge = (element, obj, excludeFrom = []) => {
95
95
  const deepMerge = (element, extend, excludeFrom = []) => {
96
96
  for (const e in extend) {
97
97
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(extend, e);
98
- if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
99
- continue;
98
+ if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) continue;
100
99
  const elementProp = element[e];
101
100
  const extendProp = extend[e];
102
101
  if ((0, import_types.isObjectLike)(elementProp) && (0, import_types.isObjectLike)(extendProp)) {
@@ -111,8 +110,7 @@ const clone = (obj, excludeFrom = []) => {
111
110
  const o = {};
112
111
  for (const prop in obj) {
113
112
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
114
- if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__"))
115
- continue;
113
+ if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) continue;
116
114
  o[prop] = obj[prop];
117
115
  }
118
116
  return o;
@@ -138,13 +136,10 @@ const deepClone = (obj, options = {}) => {
138
136
  const clone2 = targetWindow ? (0, import_types.isArray)(obj) ? new targetWindow.Array() : new targetWindow.Object() : (0, import_types.isArray)(obj) ? [] : {};
139
137
  visited.set(obj, clone2);
140
138
  for (const key in obj) {
141
- if (!Object.prototype.hasOwnProperty.call(obj, key))
142
- continue;
143
- if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
144
- continue;
139
+ if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
140
+ if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") continue;
145
141
  const value = obj[key];
146
- if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value))
147
- continue;
142
+ if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value)) continue;
148
143
  if ((0, import_node.isDOMNode)(value)) {
149
144
  clone2[key] = value;
150
145
  continue;
@@ -275,16 +270,14 @@ const objectToString = (obj = {}, indent = 0) => {
275
270
  const detachFunctionsFromObject = (obj, detached = {}) => {
276
271
  for (const prop in obj) {
277
272
  const objProp = obj[prop];
278
- if ((0, import_types.isFunction)(objProp))
279
- continue;
273
+ if ((0, import_types.isFunction)(objProp)) continue;
280
274
  else if ((0, import_types.isObject)(objProp)) {
281
275
  detached[prop] = {};
282
276
  deepStringify(objProp, detached[prop]);
283
277
  } else if ((0, import_types.isArray)(objProp)) {
284
278
  detached[prop] = [];
285
279
  objProp.forEach((v, i) => {
286
- if ((0, import_types.isFunction)(v))
287
- return;
280
+ if ((0, import_types.isFunction)(v)) return;
288
281
  if ((0, import_types.isObject)(v)) {
289
282
  detached[prop][i] = {};
290
283
  detachFunctionsFromObject(v, detached[prop][i]);
@@ -298,20 +291,38 @@ const detachFunctionsFromObject = (obj, detached = {}) => {
298
291
  }
299
292
  return detached;
300
293
  };
294
+ const hasFunction = (str) => {
295
+ if (!str) return false;
296
+ const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
297
+ if (trimmed === "") return false;
298
+ if (trimmed === "{}") return false;
299
+ if (trimmed === "[]") return false;
300
+ const patterns = [
301
+ /^\(\s*\{[^}]*\}\s*\)\s*=>/,
302
+ /^(\([^)]*\)|[^=]*)\s*=>/,
303
+ /^function[\s(]/,
304
+ /^async\s+/,
305
+ /^\(\s*function/,
306
+ /^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
307
+ ];
308
+ const isFunction2 = patterns.some((pattern) => pattern.test(trimmed));
309
+ const isObjectLiteral = trimmed.startsWith("{") && !trimmed.includes("=>");
310
+ const isArrayLiteral = trimmed.startsWith("[");
311
+ const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes("=>");
312
+ return isFunction2 && !isObjectLiteral && !isArrayLiteral && !isJSONLike;
313
+ };
301
314
  const deepDestringify = (obj, destringified = {}) => {
302
315
  for (const prop in obj) {
303
316
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
304
- if (!hasOwnProperty2)
305
- continue;
317
+ if (!hasOwnProperty2) continue;
306
318
  const objProp = obj[prop];
307
319
  if ((0, import_types.isString)(objProp)) {
308
- if ((objProp.includes("(){") || objProp.includes("() {") || objProp.includes("=>") || objProp.startsWith("()") || objProp.startsWith("async") || objProp.startsWith("function") || objProp.startsWith("(")) && !objProp.startsWith("{") && !objProp.startsWith("[")) {
320
+ if (hasFunction(objProp)) {
309
321
  try {
310
322
  const evalProp = import_globals.window.eval(`(${objProp})`);
311
323
  destringified[prop] = evalProp;
312
324
  } catch (e) {
313
- if (e)
314
- destringified[prop] = objProp;
325
+ if (e) destringified[prop] = objProp;
315
326
  }
316
327
  } else {
317
328
  destringified[prop] = objProp;
@@ -320,13 +331,12 @@ const deepDestringify = (obj, destringified = {}) => {
320
331
  destringified[prop] = [];
321
332
  objProp.forEach((arrProp) => {
322
333
  if ((0, import_types.isString)(arrProp)) {
323
- if (arrProp.includes("=>") || arrProp.includes("function") || arrProp.startsWith("(")) {
334
+ if (hasFunction(arrProp)) {
324
335
  try {
325
336
  const evalProp = import_globals.window.eval(`(${arrProp})`);
326
337
  destringified[prop].push(evalProp);
327
338
  } catch (e) {
328
- if (e)
329
- destringified[prop].push(arrProp);
339
+ if (e) destringified[prop].push(arrProp);
330
340
  }
331
341
  } else {
332
342
  destringified[prop].push(arrProp);
@@ -349,14 +359,12 @@ const stringToObject = (str, opts = { verbose: true }) => {
349
359
  try {
350
360
  return str ? import_globals.window.eval("(" + str + ")") : {};
351
361
  } catch (e) {
352
- if (opts.verbose)
353
- console.warn(e);
362
+ if (opts.verbose) console.warn(e);
354
363
  }
355
364
  };
356
365
  const diffObjects = (original, objToDiff, cache) => {
357
366
  for (const e in objToDiff) {
358
- if (e === "ref")
359
- continue;
367
+ if (e === "ref") continue;
360
368
  const originalProp = original[e];
361
369
  const objToDiffProp = objToDiff[e];
362
370
  if ((0, import_types.isObject)(originalProp) && (0, import_types.isObject)(objToDiffProp)) {
@@ -399,10 +407,8 @@ const isEmpty = (o) => Object.keys(o).length === 0;
399
407
  const isEmptyObject = (o) => (0, import_types.isObject)(o) && isEmpty(o);
400
408
  const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
401
409
  const deepDiff = (lhs, rhs) => {
402
- if (lhs === rhs)
403
- return {};
404
- if (!(0, import_types.isObjectLike)(lhs) || !(0, import_types.isObjectLike)(rhs))
405
- return rhs;
410
+ if (lhs === rhs) return {};
411
+ if (!(0, import_types.isObjectLike)(lhs) || !(0, import_types.isObjectLike)(rhs)) return rhs;
406
412
  const deletedValues = Object.keys(lhs).reduce((acc, key) => {
407
413
  if (!hasOwnProperty(rhs, key)) {
408
414
  acc[key] = void 0;
@@ -410,8 +416,7 @@ const deepDiff = (lhs, rhs) => {
410
416
  return acc;
411
417
  }, makeObjectWithoutPrototype());
412
418
  if ((0, import_types.isDate)(lhs) || (0, import_types.isDate)(rhs)) {
413
- if (lhs.valueOf() === rhs.valueOf())
414
- return {};
419
+ if (lhs.valueOf() === rhs.valueOf()) return {};
415
420
  return rhs;
416
421
  }
417
422
  return Object.keys(rhs).reduce((acc, key) => {
@@ -433,8 +438,7 @@ const overwrite = (element, params, opts = {}) => {
433
438
  const allowUnderscore = opts.preventUnderscore;
434
439
  const preventCaching = opts.preventCaching;
435
440
  for (const e in params) {
436
- if (excl.includes(e) || !allowUnderscore && e.startsWith("__"))
437
- continue;
441
+ if (excl.includes(e) || !allowUnderscore && e.startsWith("__")) continue;
438
442
  const elementProp = element[e];
439
443
  const paramsProp = params[e];
440
444
  if (paramsProp !== void 0) {
@@ -451,8 +455,7 @@ const overwrite = (element, params, opts = {}) => {
451
455
  };
452
456
  const overwriteShallow = (obj, params, excludeFrom = []) => {
453
457
  for (const e in params) {
454
- if (excludeFrom.includes(e) || e.startsWith("__"))
455
- continue;
458
+ if (excludeFrom.includes(e) || e.startsWith("__")) continue;
456
459
  obj[e] = params[e];
457
460
  }
458
461
  return obj;
@@ -463,14 +466,11 @@ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new Wea
463
466
  if (!(0, import_types.isObjectLike)(obj) || !(0, import_types.isObjectLike)(params) || (0, import_node.isDOMNode)(obj) || (0, import_node.isDOMNode)(params)) {
464
467
  return params;
465
468
  }
466
- if (visited.has(obj))
467
- return visited.get(obj);
469
+ if (visited.has(obj)) return visited.get(obj);
468
470
  visited.set(obj, obj);
469
471
  for (const e in params) {
470
- if (!Object.hasOwnProperty.call(params, e))
471
- continue;
472
- if (excl.includes(e) || forcedExclude && e.startsWith("__"))
473
- continue;
472
+ if (!Object.hasOwnProperty.call(params, e)) continue;
473
+ if (excl.includes(e) || forcedExclude && e.startsWith("__")) continue;
474
474
  const objProp = obj[e];
475
475
  const paramsProp = params[e];
476
476
  if ((0, import_node.isDOMNode)(paramsProp)) {
@@ -484,16 +484,14 @@ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new Wea
484
484
  return obj;
485
485
  };
486
486
  const mergeIfExisted = (a, b) => {
487
- if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b))
488
- return deepMerge(a, b);
487
+ if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b)) return deepMerge(a, b);
489
488
  return a || b;
490
489
  };
491
490
  const flattenRecursive = (param, prop, stack = []) => {
492
491
  const objectized = (0, import_array.mergeAndCloneIfArray)(param);
493
492
  stack.push(objectized);
494
493
  const extendOfExtend = objectized[prop];
495
- if (extendOfExtend)
496
- flattenRecursive(extendOfExtend, prop, stack);
494
+ if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack);
497
495
  delete objectized[prop];
498
496
  return stack;
499
497
  };
@@ -524,31 +522,24 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
524
522
  return true;
525
523
  };
526
524
  const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
527
- if (obj1 === obj2)
528
- return true;
529
- if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2))
530
- return false;
531
- if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2))
532
- return obj1 === obj2;
525
+ if (obj1 === obj2) return true;
526
+ if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2)) return false;
527
+ if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2)) return obj1 === obj2;
533
528
  const stack = [[obj1, obj2]];
534
529
  const visited = /* @__PURE__ */ new WeakSet();
535
530
  while (stack.length > 0) {
536
531
  const [current1, current2] = stack.pop();
537
- if (visited.has(current1))
538
- continue;
532
+ if (visited.has(current1)) continue;
539
533
  visited.add(current1);
540
534
  const keys1 = Object.keys(current1).filter((key) => !ignoredKeys.includes(key));
541
535
  const keys2 = Object.keys(current2).filter((key) => !ignoredKeys.includes(key));
542
- if (keys1.length !== keys2.length)
543
- return false;
536
+ if (keys1.length !== keys2.length) return false;
544
537
  for (const key of keys1) {
545
- if (!Object.prototype.hasOwnProperty.call(current2, key))
546
- return false;
538
+ if (!Object.prototype.hasOwnProperty.call(current2, key)) return false;
547
539
  const value1 = current1[key];
548
540
  const value2 = current2[key];
549
541
  if ((0, import_node.isDOMNode)(value1) || (0, import_node.isDOMNode)(value2)) {
550
- if (value1 !== value2)
551
- return false;
542
+ if (value1 !== value2) return false;
552
543
  } else if ((0, import_types.isObjectLike)(value1) && (0, import_types.isObjectLike)(value2)) {
553
544
  if (value1 !== value2) {
554
545
  stack.push([value1, value2]);
@@ -561,8 +552,7 @@ const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
561
552
  return true;
562
553
  };
563
554
  const removeFromObject = (obj, props) => {
564
- if (props === void 0 || props === null)
565
- return obj;
555
+ if (props === void 0 || props === null) return obj;
566
556
  if ((0, import_types.is)(props)("string", "number")) {
567
557
  delete obj[props];
568
558
  } else if ((0, import_types.isArray)(props)) {
@@ -593,7 +583,7 @@ const createNestedObject = (arr, lastValue) => {
593
583
  if (!obj[value]) {
594
584
  obj[value] = {};
595
585
  }
596
- if (index === arr.length - 1 && lastValue) {
586
+ if (index === arr.length - 1 && lastValue !== void 0) {
597
587
  obj[value] = lastValue;
598
588
  }
599
589
  return obj[value];
@@ -47,8 +47,7 @@ const brackRegex = {
47
47
  3: /\{\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}\}/g
48
48
  };
49
49
  function replaceLiteralsWithObjectFields(str, options = {}, forcedState) {
50
- if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{"))
51
- return str;
50
+ if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{")) return str;
52
51
  const reg = brackRegex[options.bracketsLength || 2];
53
52
  const obj = forcedState || (this == null ? void 0 : this.state) || {};
54
53
  return str.replace(reg, (_, parentPath, variable) => {
package/dist/cjs/types.js CHANGED
@@ -36,8 +36,7 @@ __export(types_exports, {
36
36
  module.exports = __toCommonJS(types_exports);
37
37
  var import_node = require("./node.js");
38
38
  const isObject = (arg) => {
39
- if (arg === null)
40
- return false;
39
+ if (arg === null) return false;
41
40
  return typeof arg === "object" && arg.constructor === Object;
42
41
  };
43
42
  const isString = (arg) => typeof arg === "string";
@@ -48,8 +47,7 @@ const isNull = (arg) => arg === null;
48
47
  const isArray = (arg) => Array.isArray(arg);
49
48
  const isDate = (d) => d instanceof Date;
50
49
  const isObjectLike = (arg) => {
51
- if (arg === null)
52
- return false;
50
+ if (arg === null) return false;
53
51
  return typeof arg === "object";
54
52
  };
55
53
  const isDefined = (arg) => {
package/dist/esm/array.js CHANGED
@@ -9,8 +9,7 @@ const getFrequencyInArray = (arr, value) => {
9
9
  }, 0);
10
10
  };
11
11
  const removeFromArray = (arr, index) => {
12
- if (isString(index))
13
- index = parseInt(index);
12
+ if (isString(index)) index = parseInt(index);
14
13
  if (isNumber(index)) {
15
14
  if (index < 0 || index >= arr.length || isNaN(index)) {
16
15
  throw new Error("Invalid index");
@@ -43,8 +42,7 @@ const cutArrayBeforeValue = (arr, value) => {
43
42
  return arr;
44
43
  };
45
44
  const cutArrayAfterValue = (arr, value) => {
46
- if (!isArray(arr))
47
- return;
45
+ if (!isArray(arr)) return;
48
46
  const index = arr.indexOf(value);
49
47
  if (index !== -1) {
50
48
  return arr.slice(index + 1);
@@ -103,8 +101,7 @@ const filterArraysFast = (sourceArr, excludeArr) => {
103
101
  return sourceArr.filter((item) => !excludeSet.has(item));
104
102
  };
105
103
  const checkIfStringIsInArray = (string, arr) => {
106
- if (!string)
107
- return;
104
+ if (!string) return;
108
105
  return arr.filter((v) => string.includes(v)).length;
109
106
  };
110
107
  export {
@@ -23,21 +23,18 @@ import { isArray, isFunction, isObject, isString } from "./types.js";
23
23
  const ENV = "development";
24
24
  const checkIfKeyIsComponent = (key) => {
25
25
  const isFirstKeyString = isString(key);
26
- if (!isFirstKeyString)
27
- return;
26
+ if (!isFirstKeyString) return;
28
27
  const firstCharKey = key.slice(0, 1);
29
28
  return /^[A-Z]*$/.test(firstCharKey);
30
29
  };
31
30
  const checkIfKeyIsProperty = (key) => {
32
31
  const isFirstKeyString = isString(key);
33
- if (!isFirstKeyString)
34
- return;
32
+ if (!isFirstKeyString) return;
35
33
  const firstCharKey = key.slice(0, 1);
36
34
  return /^[a-z]*$/.test(firstCharKey);
37
35
  };
38
36
  const addAdditionalExtend = (newExtend, element) => {
39
- if (!newExtend)
40
- return element;
37
+ if (!newExtend) return element;
41
38
  const { extend: elementExtend } = element;
42
39
  const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend];
43
40
  const receivedArray = isArray(newExtend) ? newExtend : [newExtend];
@@ -62,8 +59,7 @@ const checkIfSugar = (element, parent, key) => {
62
59
  const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
63
60
  if (hasComponentAttrs && (childProps || extendProps || children || childExtends)) {
64
61
  const logErr = (_a = parent || element) == null ? void 0 : _a.error;
65
- if (logErr)
66
- logErr.call(element, "Sugar component includes params for builtin components", { verbose: true });
62
+ if (logErr) logErr.call(element, "Sugar component includes params for builtin components", { verbose: true });
67
63
  }
68
64
  return !hasComponentAttrs || childProps || extendProps || children || childExtends;
69
65
  };
@@ -76,8 +72,7 @@ const extendizeByKey = (element, parent, key) => {
76
72
  const isSugar = checkIfSugar(element, parent, key);
77
73
  const extendFromKey = extractComponentKeyFromKey(key);
78
74
  const isExtendKeyComponent = context && context.components[extendFromKey];
79
- if (element === isExtendKeyComponent)
80
- return element;
75
+ if (element === isExtendKeyComponent) return element;
81
76
  else if (isSugar) {
82
77
  const newElem = addAdditionalExtend(element.extends, {
83
78
  extend: extendFromKey,
@@ -100,8 +95,7 @@ const extendizeByKey = (element, parent, key) => {
100
95
  newElem.if = newElem.props.if;
101
96
  delete newElem.props.if;
102
97
  }
103
- if (childExtends)
104
- newElem.childExtend = childExtends;
98
+ if (childExtends) newElem.childExtend = childExtends;
105
99
  return newElem;
106
100
  } else if (!extend || extend === true) {
107
101
  return __spreadProps(__spreadValues({}, element), {
@@ -123,8 +117,7 @@ function getCapitalCaseKeys(obj) {
123
117
  }
124
118
  const addChildrenIfNotInOriginal = (element, parent, key) => {
125
119
  const childElems = getCapitalCaseKeys(element.props);
126
- if (!childElems.length)
127
- return element;
120
+ if (!childElems.length) return element;
128
121
  for (const i in childElems) {
129
122
  const childKey = childElems[i];
130
123
  const childElem = element[childKey];
@@ -133,16 +126,12 @@ const addChildrenIfNotInOriginal = (element, parent, key) => {
133
126
  element[childKey] = val;
134
127
  delete element.props[childKey];
135
128
  };
136
- if (newChild == null ? void 0 : newChild.ignoreExtend)
137
- continue;
138
- if (newChild === null)
139
- assignChild(null);
140
- else if (!childElem)
141
- assignChild(deepClone(newChild));
129
+ if (newChild == null ? void 0 : newChild.ignoreExtend) continue;
130
+ if (newChild === null) assignChild(null);
131
+ else if (!childElem) assignChild(deepClone(newChild));
142
132
  else {
143
133
  const isSugarChildElem = checkIfSugar(childElem, parent, key);
144
- if (isSugarChildElem)
145
- continue;
134
+ if (isSugarChildElem) continue;
146
135
  assignChild({
147
136
  extend: element[childKey],
148
137
  props: newChild
@@ -155,15 +144,13 @@ const applyKeyComponentAsExtend = (element, parent, key) => {
155
144
  };
156
145
  const applyComponentFromContext = (element, parent, options) => {
157
146
  const { context } = element;
158
- if (!context || !context.components)
159
- return;
147
+ if (!context || !context.components) return;
160
148
  const { components } = context;
161
149
  const { extend } = element;
162
150
  const execExtend = exec(extend, element);
163
151
  if (isString(execExtend)) {
164
152
  const componentExists = components[execExtend] || components["smbls." + execExtend];
165
- if (componentExists)
166
- element.extend = componentExists;
153
+ if (componentExists) element.extend = componentExists;
167
154
  else {
168
155
  if ((ENV === "test" || ENV === "development") && options.verbose) {
169
156
  console.warn(execExtend, "is not in library", components, element);
@@ -174,15 +161,13 @@ const applyComponentFromContext = (element, parent, options) => {
174
161
  }
175
162
  };
176
163
  const isVariant = (param) => {
177
- if (!isString(param))
178
- return;
164
+ if (!isString(param)) return;
179
165
  const firstCharKey = param.slice(0, 1);
180
166
  return firstCharKey === ".";
181
167
  };
182
168
  const hasVariantProp = (element) => {
183
169
  const { props } = element;
184
- if (isObject(props) && isString(props.variant))
185
- return true;
170
+ if (isObject(props) && isString(props.variant)) return true;
186
171
  };
187
172
  const getChildrenComponentsByKey = (key, el) => {
188
173
  if (key === el.key || el.__ref.__componentKey === key) {
@@ -191,14 +176,12 @@ const getChildrenComponentsByKey = (key, el) => {
191
176
  if (el.extend) {
192
177
  const foundString = isString(el.extend) && el.extend === key;
193
178
  const foundInArray = isArray(el.extend) && el.extend.filter((v) => v === key).length;
194
- if (foundString || foundInArray)
195
- return el;
179
+ if (foundString || foundInArray) return el;
196
180
  }
197
181
  if (el.parent && el.parent.childExtend) {
198
182
  const foundString = isString(el.parent.childExtend) && el.parent.childExtend === key;
199
183
  const foundInArray = isArray(el.parent.childExtend) && el.parent.childExtend.filter((v) => v === key).length;
200
- if (foundString || foundInArray)
201
- return el;
184
+ if (foundString || foundInArray) return el;
202
185
  }
203
186
  };
204
187
  const getExtendsInElement = (obj) => {
@@ -230,10 +213,8 @@ const setContentKey = (el, opts = {}) => {
230
213
  const contentElementKey = opts.contentElementKey;
231
214
  if (contentElementKey !== "content" && contentElementKey !== ref.contentElementKey || !ref.contentElementKey) {
232
215
  ref.contentElementKey = contentElementKey || "content";
233
- } else
234
- ref.contentElementKey = "content";
235
- if (contentElementKey !== "content")
236
- opts.contentElementKey = "content";
216
+ } else ref.contentElementKey = "content";
217
+ if (contentElementKey !== "content") opts.contentElementKey = "content";
237
218
  return ref.contentElementKey;
238
219
  };
239
220
  export {
@@ -2,31 +2,26 @@ import { isUndefined } from "./types.js";
2
2
  import { document } from "./globals.js";
3
3
  const isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))();
4
4
  const setCookie = (cname, cvalue, exdays = 365) => {
5
- if (isUndefined(document) || isUndefined(document.cookie))
6
- return;
5
+ if (isUndefined(document) || isUndefined(document.cookie)) return;
7
6
  const d = /* @__PURE__ */ new Date();
8
7
  d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1e3);
9
8
  const expires = `expires=${d.toUTCString()}`;
10
9
  document.cookie = `${cname}=${cvalue};${expires};path=/`;
11
10
  };
12
11
  const getCookie = (cname) => {
13
- if (isUndefined(document) || isUndefined(document.cookie))
14
- return;
12
+ if (isUndefined(document) || isUndefined(document.cookie)) return;
15
13
  const name = `${cname}=`;
16
14
  const decodedCookie = decodeURIComponent(document.cookie);
17
15
  const ca = decodedCookie.split(";");
18
16
  for (let i = 0; i < ca.length; i++) {
19
17
  let c = ca[i];
20
- while (c.charAt(0) === " ")
21
- c = c.substring(1);
22
- if (c.indexOf(name) === 0)
23
- return c.substring(name.length, c.length);
18
+ while (c.charAt(0) === " ") c = c.substring(1);
19
+ if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
24
20
  }
25
21
  return "";
26
22
  };
27
23
  const removeCookie = (cname) => {
28
- if (isUndefined(document) || isUndefined(document.cookie))
29
- return;
24
+ if (isUndefined(document) || isUndefined(document.cookie)) return;
30
25
  document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
31
26
  };
32
27
  function getLocalStorage(key) {
@@ -5,14 +5,12 @@ function debounce(func, wait, immediate) {
5
5
  const args = arguments;
6
6
  const later = function() {
7
7
  timeout = null;
8
- if (!immediate)
9
- func.apply(context, args);
8
+ if (!immediate) func.apply(context, args);
10
9
  };
11
10
  const callNow = immediate && !timeout;
12
11
  clearTimeout(timeout);
13
12
  timeout = setTimeout(later, wait);
14
- if (callNow)
15
- func.apply(context, args);
13
+ if (callNow) func.apply(context, args);
16
14
  };
17
15
  }
18
16
  const debounceOnContext = (element, func, timeout = 300) => {
package/dist/esm/key.js CHANGED
@@ -1,4 +1,4 @@
1
- const generateKey = function() {
1
+ const generateKey = /* @__PURE__ */ function() {
2
2
  let index = 0;
3
3
  function newId() {
4
4
  index++;
package/dist/esm/log.js CHANGED
@@ -1,6 +1,5 @@
1
1
  const logIf = (bool, ...arg) => {
2
- if (bool)
3
- arg.map((v) => console.log(v));
2
+ if (bool) arg.map((v) => console.log(v));
4
3
  };
5
4
  const logGroupIf = (bool, key, ...arg) => {
6
5
  if (bool) {
@@ -52,8 +52,7 @@ const map = (obj, extention, element) => {
52
52
  const merge = (element, obj, excludeFrom = []) => {
53
53
  for (const e in obj) {
54
54
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, e);
55
- if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
56
- continue;
55
+ if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) continue;
57
56
  const elementProp = element[e];
58
57
  const objProp = obj[e];
59
58
  if (elementProp === void 0) {
@@ -65,8 +64,7 @@ const merge = (element, obj, excludeFrom = []) => {
65
64
  const deepMerge = (element, extend, excludeFrom = []) => {
66
65
  for (const e in extend) {
67
66
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(extend, e);
68
- if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
69
- continue;
67
+ if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) continue;
70
68
  const elementProp = element[e];
71
69
  const extendProp = extend[e];
72
70
  if (isObjectLike(elementProp) && isObjectLike(extendProp)) {
@@ -81,8 +79,7 @@ const clone = (obj, excludeFrom = []) => {
81
79
  const o = {};
82
80
  for (const prop in obj) {
83
81
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
84
- if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__"))
85
- continue;
82
+ if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) continue;
86
83
  o[prop] = obj[prop];
87
84
  }
88
85
  return o;
@@ -108,13 +105,10 @@ const deepClone = (obj, options = {}) => {
108
105
  const clone2 = targetWindow ? isArray(obj) ? new targetWindow.Array() : new targetWindow.Object() : isArray(obj) ? [] : {};
109
106
  visited.set(obj, clone2);
110
107
  for (const key in obj) {
111
- if (!Object.prototype.hasOwnProperty.call(obj, key))
112
- continue;
113
- if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
114
- continue;
108
+ if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
109
+ if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") continue;
115
110
  const value = obj[key];
116
- if (cleanUndefined && isUndefined(value) || cleanNull && isNull(value))
117
- continue;
111
+ if (cleanUndefined && isUndefined(value) || cleanNull && isNull(value)) continue;
118
112
  if (isDOMNode(value)) {
119
113
  clone2[key] = value;
120
114
  continue;
@@ -244,16 +238,14 @@ const objectToString = (obj = {}, indent = 0) => {
244
238
  const detachFunctionsFromObject = (obj, detached = {}) => {
245
239
  for (const prop in obj) {
246
240
  const objProp = obj[prop];
247
- if (isFunction(objProp))
248
- continue;
241
+ if (isFunction(objProp)) continue;
249
242
  else if (isObject(objProp)) {
250
243
  detached[prop] = {};
251
244
  deepStringify(objProp, detached[prop]);
252
245
  } else if (isArray(objProp)) {
253
246
  detached[prop] = [];
254
247
  objProp.forEach((v, i) => {
255
- if (isFunction(v))
256
- return;
248
+ if (isFunction(v)) return;
257
249
  if (isObject(v)) {
258
250
  detached[prop][i] = {};
259
251
  detachFunctionsFromObject(v, detached[prop][i]);
@@ -267,20 +259,38 @@ const detachFunctionsFromObject = (obj, detached = {}) => {
267
259
  }
268
260
  return detached;
269
261
  };
262
+ const hasFunction = (str) => {
263
+ if (!str) return false;
264
+ const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
265
+ if (trimmed === "") return false;
266
+ if (trimmed === "{}") return false;
267
+ if (trimmed === "[]") return false;
268
+ const patterns = [
269
+ /^\(\s*\{[^}]*\}\s*\)\s*=>/,
270
+ /^(\([^)]*\)|[^=]*)\s*=>/,
271
+ /^function[\s(]/,
272
+ /^async\s+/,
273
+ /^\(\s*function/,
274
+ /^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
275
+ ];
276
+ const isFunction2 = patterns.some((pattern) => pattern.test(trimmed));
277
+ const isObjectLiteral = trimmed.startsWith("{") && !trimmed.includes("=>");
278
+ const isArrayLiteral = trimmed.startsWith("[");
279
+ const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes("=>");
280
+ return isFunction2 && !isObjectLiteral && !isArrayLiteral && !isJSONLike;
281
+ };
270
282
  const deepDestringify = (obj, destringified = {}) => {
271
283
  for (const prop in obj) {
272
284
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
273
- if (!hasOwnProperty2)
274
- continue;
285
+ if (!hasOwnProperty2) continue;
275
286
  const objProp = obj[prop];
276
287
  if (isString(objProp)) {
277
- if ((objProp.includes("(){") || objProp.includes("() {") || objProp.includes("=>") || objProp.startsWith("()") || objProp.startsWith("async") || objProp.startsWith("function") || objProp.startsWith("(")) && !objProp.startsWith("{") && !objProp.startsWith("[")) {
288
+ if (hasFunction(objProp)) {
278
289
  try {
279
290
  const evalProp = window.eval(`(${objProp})`);
280
291
  destringified[prop] = evalProp;
281
292
  } catch (e) {
282
- if (e)
283
- destringified[prop] = objProp;
293
+ if (e) destringified[prop] = objProp;
284
294
  }
285
295
  } else {
286
296
  destringified[prop] = objProp;
@@ -289,13 +299,12 @@ const deepDestringify = (obj, destringified = {}) => {
289
299
  destringified[prop] = [];
290
300
  objProp.forEach((arrProp) => {
291
301
  if (isString(arrProp)) {
292
- if (arrProp.includes("=>") || arrProp.includes("function") || arrProp.startsWith("(")) {
302
+ if (hasFunction(arrProp)) {
293
303
  try {
294
304
  const evalProp = window.eval(`(${arrProp})`);
295
305
  destringified[prop].push(evalProp);
296
306
  } catch (e) {
297
- if (e)
298
- destringified[prop].push(arrProp);
307
+ if (e) destringified[prop].push(arrProp);
299
308
  }
300
309
  } else {
301
310
  destringified[prop].push(arrProp);
@@ -318,14 +327,12 @@ const stringToObject = (str, opts = { verbose: true }) => {
318
327
  try {
319
328
  return str ? window.eval("(" + str + ")") : {};
320
329
  } catch (e) {
321
- if (opts.verbose)
322
- console.warn(e);
330
+ if (opts.verbose) console.warn(e);
323
331
  }
324
332
  };
325
333
  const diffObjects = (original, objToDiff, cache) => {
326
334
  for (const e in objToDiff) {
327
- if (e === "ref")
328
- continue;
335
+ if (e === "ref") continue;
329
336
  const originalProp = original[e];
330
337
  const objToDiffProp = objToDiff[e];
331
338
  if (isObject(originalProp) && isObject(objToDiffProp)) {
@@ -368,10 +375,8 @@ const isEmpty = (o) => Object.keys(o).length === 0;
368
375
  const isEmptyObject = (o) => isObject(o) && isEmpty(o);
369
376
  const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
370
377
  const deepDiff = (lhs, rhs) => {
371
- if (lhs === rhs)
372
- return {};
373
- if (!isObjectLike(lhs) || !isObjectLike(rhs))
374
- return rhs;
378
+ if (lhs === rhs) return {};
379
+ if (!isObjectLike(lhs) || !isObjectLike(rhs)) return rhs;
375
380
  const deletedValues = Object.keys(lhs).reduce((acc, key) => {
376
381
  if (!hasOwnProperty(rhs, key)) {
377
382
  acc[key] = void 0;
@@ -379,8 +384,7 @@ const deepDiff = (lhs, rhs) => {
379
384
  return acc;
380
385
  }, makeObjectWithoutPrototype());
381
386
  if (isDate(lhs) || isDate(rhs)) {
382
- if (lhs.valueOf() === rhs.valueOf())
383
- return {};
387
+ if (lhs.valueOf() === rhs.valueOf()) return {};
384
388
  return rhs;
385
389
  }
386
390
  return Object.keys(rhs).reduce((acc, key) => {
@@ -402,8 +406,7 @@ const overwrite = (element, params, opts = {}) => {
402
406
  const allowUnderscore = opts.preventUnderscore;
403
407
  const preventCaching = opts.preventCaching;
404
408
  for (const e in params) {
405
- if (excl.includes(e) || !allowUnderscore && e.startsWith("__"))
406
- continue;
409
+ if (excl.includes(e) || !allowUnderscore && e.startsWith("__")) continue;
407
410
  const elementProp = element[e];
408
411
  const paramsProp = params[e];
409
412
  if (paramsProp !== void 0) {
@@ -420,8 +423,7 @@ const overwrite = (element, params, opts = {}) => {
420
423
  };
421
424
  const overwriteShallow = (obj, params, excludeFrom = []) => {
422
425
  for (const e in params) {
423
- if (excludeFrom.includes(e) || e.startsWith("__"))
424
- continue;
426
+ if (excludeFrom.includes(e) || e.startsWith("__")) continue;
425
427
  obj[e] = params[e];
426
428
  }
427
429
  return obj;
@@ -432,14 +434,11 @@ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new Wea
432
434
  if (!isObjectLike(obj) || !isObjectLike(params) || isDOMNode(obj) || isDOMNode(params)) {
433
435
  return params;
434
436
  }
435
- if (visited.has(obj))
436
- return visited.get(obj);
437
+ if (visited.has(obj)) return visited.get(obj);
437
438
  visited.set(obj, obj);
438
439
  for (const e in params) {
439
- if (!Object.hasOwnProperty.call(params, e))
440
- continue;
441
- if (excl.includes(e) || forcedExclude && e.startsWith("__"))
442
- continue;
440
+ if (!Object.hasOwnProperty.call(params, e)) continue;
441
+ if (excl.includes(e) || forcedExclude && e.startsWith("__")) continue;
443
442
  const objProp = obj[e];
444
443
  const paramsProp = params[e];
445
444
  if (isDOMNode(paramsProp)) {
@@ -453,16 +452,14 @@ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new Wea
453
452
  return obj;
454
453
  };
455
454
  const mergeIfExisted = (a, b) => {
456
- if (isObjectLike(a) && isObjectLike(b))
457
- return deepMerge(a, b);
455
+ if (isObjectLike(a) && isObjectLike(b)) return deepMerge(a, b);
458
456
  return a || b;
459
457
  };
460
458
  const flattenRecursive = (param, prop, stack = []) => {
461
459
  const objectized = mergeAndCloneIfArray(param);
462
460
  stack.push(objectized);
463
461
  const extendOfExtend = objectized[prop];
464
- if (extendOfExtend)
465
- flattenRecursive(extendOfExtend, prop, stack);
462
+ if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack);
466
463
  delete objectized[prop];
467
464
  return stack;
468
465
  };
@@ -493,31 +490,24 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
493
490
  return true;
494
491
  };
495
492
  const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
496
- if (obj1 === obj2)
497
- return true;
498
- if (!isObjectLike(obj1) || !isObjectLike(obj2))
499
- return false;
500
- if (isDOMNode(obj1) || isDOMNode(obj2))
501
- return obj1 === obj2;
493
+ if (obj1 === obj2) return true;
494
+ if (!isObjectLike(obj1) || !isObjectLike(obj2)) return false;
495
+ if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2;
502
496
  const stack = [[obj1, obj2]];
503
497
  const visited = /* @__PURE__ */ new WeakSet();
504
498
  while (stack.length > 0) {
505
499
  const [current1, current2] = stack.pop();
506
- if (visited.has(current1))
507
- continue;
500
+ if (visited.has(current1)) continue;
508
501
  visited.add(current1);
509
502
  const keys1 = Object.keys(current1).filter((key) => !ignoredKeys.includes(key));
510
503
  const keys2 = Object.keys(current2).filter((key) => !ignoredKeys.includes(key));
511
- if (keys1.length !== keys2.length)
512
- return false;
504
+ if (keys1.length !== keys2.length) return false;
513
505
  for (const key of keys1) {
514
- if (!Object.prototype.hasOwnProperty.call(current2, key))
515
- return false;
506
+ if (!Object.prototype.hasOwnProperty.call(current2, key)) return false;
516
507
  const value1 = current1[key];
517
508
  const value2 = current2[key];
518
509
  if (isDOMNode(value1) || isDOMNode(value2)) {
519
- if (value1 !== value2)
520
- return false;
510
+ if (value1 !== value2) return false;
521
511
  } else if (isObjectLike(value1) && isObjectLike(value2)) {
522
512
  if (value1 !== value2) {
523
513
  stack.push([value1, value2]);
@@ -530,8 +520,7 @@ const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
530
520
  return true;
531
521
  };
532
522
  const removeFromObject = (obj, props) => {
533
- if (props === void 0 || props === null)
534
- return obj;
523
+ if (props === void 0 || props === null) return obj;
535
524
  if (is(props)("string", "number")) {
536
525
  delete obj[props];
537
526
  } else if (isArray(props)) {
@@ -562,7 +551,7 @@ const createNestedObject = (arr, lastValue) => {
562
551
  if (!obj[value]) {
563
552
  obj[value] = {};
564
553
  }
565
- if (index === arr.length - 1 && lastValue) {
554
+ if (index === arr.length - 1 && lastValue !== void 0) {
566
555
  obj[value] = lastValue;
567
556
  }
568
557
  return obj[value];
@@ -680,6 +669,7 @@ export {
680
669
  exec,
681
670
  flattenRecursive,
682
671
  getInObjectByPath,
672
+ hasFunction,
683
673
  hasOwnProperty,
684
674
  isCyclic,
685
675
  isEmpty,
@@ -15,8 +15,7 @@ const brackRegex = {
15
15
  3: /\{\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}\}/g
16
16
  };
17
17
  function replaceLiteralsWithObjectFields(str, options = {}, forcedState) {
18
- if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{"))
19
- return str;
18
+ if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{")) return str;
20
19
  const reg = brackRegex[options.bracketsLength || 2];
21
20
  const obj = forcedState || (this == null ? void 0 : this.state) || {};
22
21
  return str.replace(reg, (_, parentPath, variable) => {
package/dist/esm/types.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { isHtmlElement, isNode } from "./node.js";
2
2
  const isObject = (arg) => {
3
- if (arg === null)
4
- return false;
3
+ if (arg === null) return false;
5
4
  return typeof arg === "object" && arg.constructor === Object;
6
5
  };
7
6
  const isString = (arg) => typeof arg === "string";
@@ -12,8 +11,7 @@ const isNull = (arg) => arg === null;
12
11
  const isArray = (arg) => Array.isArray(arg);
13
12
  const isDate = (d) => d instanceof Date;
14
13
  const isObjectLike = (arg) => {
15
- if (arg === null)
16
- return false;
14
+ if (arg === null) return false;
17
15
  return typeof arg === "object";
18
16
  };
19
17
  const isDefined = (arg) => {
package/object.js CHANGED
@@ -311,30 +311,47 @@ export const detachFunctionsFromObject = (obj, detached = {}) => {
311
311
  return detached
312
312
  }
313
313
 
314
- /**
315
- * Detringify object
316
- */
314
+ export const hasFunction = (str) => {
315
+ if (!str) return false
316
+
317
+ const trimmed = str.trim().replace(/\n\s*/g, ' ').trim()
318
+
319
+ if (trimmed === '') return false
320
+ if (trimmed === '{}') return false
321
+ if (trimmed === '[]') return false
322
+
323
+ const patterns = [
324
+ /^\(\s*\{[^}]*\}\s*\)\s*=>/,
325
+ /^(\([^)]*\)|[^=]*)\s*=>/,
326
+ /^function[\s(]/,
327
+ /^async\s+/,
328
+ /^\(\s*function/,
329
+ /^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
330
+ ]
331
+
332
+ const isFunction = patterns.some(pattern => pattern.test(trimmed))
333
+ const isObjectLiteral = trimmed.startsWith('{') && !trimmed.includes('=>')
334
+ const isArrayLiteral = trimmed.startsWith('[')
335
+ const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes('=>')
336
+
337
+ return isFunction && !isObjectLiteral && !isArrayLiteral && !isJSONLike
338
+ }
339
+
317
340
  export const deepDestringify = (obj, destringified = {}) => {
318
341
  for (const prop in obj) {
319
342
  const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop)
320
343
  if (!hasOwnProperty) continue
344
+
321
345
  const objProp = obj[prop]
346
+
322
347
  if (isString(objProp)) {
323
- if ((
324
- objProp.includes('(){') ||
325
- objProp.includes('() {') ||
326
- objProp.includes('=>') ||
327
- objProp.startsWith('()') ||
328
- objProp.startsWith('async') ||
329
- objProp.startsWith('function') ||
330
- objProp.startsWith('(')
331
- ) &&
332
- !objProp.startsWith('{') && !objProp.startsWith('[')
333
- ) {
348
+ if (hasFunction(objProp)) {
334
349
  try {
335
350
  const evalProp = window.eval(`(${objProp})`)
336
351
  destringified[prop] = evalProp
337
- } catch (e) { if (e) destringified[prop] = objProp }
352
+ } catch (e) {
353
+ if (e) destringified[prop] = objProp
354
+ }
338
355
  } else {
339
356
  destringified[prop] = objProp
340
357
  }
@@ -342,11 +359,13 @@ export const deepDestringify = (obj, destringified = {}) => {
342
359
  destringified[prop] = []
343
360
  objProp.forEach((arrProp) => {
344
361
  if (isString(arrProp)) {
345
- if (arrProp.includes('=>') || arrProp.includes('function') || arrProp.startsWith('(')) {
362
+ if (hasFunction(arrProp)) {
346
363
  try {
347
- const evalProp = window.eval(`(${arrProp})`) // use parentheses to convert string to function expression
364
+ const evalProp = window.eval(`(${arrProp})`)
348
365
  destringified[prop].push(evalProp)
349
- } catch (e) { if (e) destringified[prop].push(arrProp) }
366
+ } catch (e) {
367
+ if (e) destringified[prop].push(arrProp)
368
+ }
350
369
  } else {
351
370
  destringified[prop].push(arrProp)
352
371
  }
@@ -708,7 +727,7 @@ export const createNestedObject = (arr, lastValue) => {
708
727
  if (!obj[value]) {
709
728
  obj[value] = {}
710
729
  }
711
- if (index === arr.length - 1 && lastValue) {
730
+ if (index === arr.length - 1 && lastValue !== undefined) {
712
731
  obj[value] = lastValue
713
732
  }
714
733
  return obj[value]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.185",
3
+ "version": "2.5.200",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -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": "ccab034f188b6a1f55f741c0b29a9d3b0c9bee6f",
27
+ "gitHead": "0afb63ec375f0526f47ff300885de393138b01e8",
28
28
  "devDependencies": {
29
29
  "@babel/core": "^7.12.0"
30
30
  }