@domql/utils
Advanced tools
@@ -160,3 +160,3 @@ 'use strict' | ||
else { | ||
if ((ENV === 'test' || ENV === 'development') && options.verbose) { | ||
if ((ENV === 'testing' || ENV === 'development') && options.verbose) { | ||
console.warn(execExtend, 'is not in library', components, element) | ||
@@ -163,0 +163,0 @@ console.warn('replacing with ', {}) |
@@ -51,3 +51,4 @@ "use strict"; | ||
const removeFromArray = (arr, index) => { | ||
if ((0, import_types.isString)(index)) index = parseInt(index); | ||
if ((0, import_types.isString)(index)) | ||
index = parseInt(index); | ||
if ((0, import_types.isNumber)(index)) { | ||
@@ -85,3 +86,4 @@ if (index < 0 || index >= arr.length || isNaN(index)) { | ||
const cutArrayAfterValue = (arr, value) => { | ||
if (!(0, import_types.isArray)(arr)) return; | ||
if (!(0, import_types.isArray)(arr)) | ||
return; | ||
const index = arr.indexOf(value); | ||
@@ -145,4 +147,5 @@ if (index !== -1) { | ||
const checkIfStringIsInArray = (string, arr) => { | ||
if (!string) return; | ||
if (!string) | ||
return; | ||
return arr.filter((v) => string.includes(v)).length; | ||
}; |
@@ -44,3 +44,4 @@ "use strict"; | ||
const isFirstKeyString = (0, import_types.isString)(key); | ||
if (!isFirstKeyString) return; | ||
if (!isFirstKeyString) | ||
return; | ||
const firstCharKey = key.slice(0, 1); | ||
@@ -51,3 +52,4 @@ return /^[A-Z]*$/.test(firstCharKey); | ||
const isFirstKeyString = (0, import_types.isString)(key); | ||
if (!isFirstKeyString) return; | ||
if (!isFirstKeyString) | ||
return; | ||
const firstCharKey = key.slice(0, 1); | ||
@@ -57,3 +59,4 @@ return /^[a-z]*$/.test(firstCharKey); | ||
const addAdditionalExtend = (newExtend, element) => { | ||
if (!newExtend) return element; | ||
if (!newExtend) | ||
return element; | ||
const { extend: elementExtend } = element; | ||
@@ -83,3 +86,4 @@ const originalArray = (0, import_types.isArray)(elementExtend) ? elementExtend : [elementExtend]; | ||
const logErr = (_a = parent || element) == null ? void 0 : _a.error; | ||
if (logErr) logErr.call(element, "Sugar component includes params for builtin components", { verbose: true }); | ||
if (logErr) | ||
logErr.call(element, "Sugar component includes params for builtin components", { verbose: true }); | ||
} | ||
@@ -97,3 +101,4 @@ return !hasComponentAttrs || childProps || extendProps || children || childExtends; | ||
const isExtendKeyComponent = context && context.components[extendFromKey]; | ||
if (element === isExtendKeyComponent) return element; | ||
if (element === isExtendKeyComponent) | ||
return element; | ||
else if (isSugar) { | ||
@@ -121,3 +126,4 @@ const newElem = addAdditionalExtend(element.extends, { | ||
} | ||
if (childExtends) newElem.childExtend = childExtends; | ||
if (childExtends) | ||
newElem.childExtend = childExtends; | ||
return newElem; | ||
@@ -145,3 +151,4 @@ } else if (!extend || extend === true) { | ||
const childElems = getCapitalCaseKeys(element.props); | ||
if (!childElems.length) return element; | ||
if (!childElems.length) | ||
return element; | ||
for (const i in childElems) { | ||
@@ -155,8 +162,12 @@ const childKey = childElems[i]; | ||
}; | ||
if (newChild == null ? void 0 : newChild.ignoreExtend) continue; | ||
if (newChild === null) assignChild(null); | ||
else if (!childElem) assignChild((0, import_object.deepClone)(newChild)); | ||
if (newChild == null ? void 0 : newChild.ignoreExtend) | ||
continue; | ||
if (newChild === null) | ||
assignChild(null); | ||
else if (!childElem) | ||
assignChild((0, import_object.deepClone)(newChild)); | ||
else { | ||
const isSugarChildElem = checkIfSugar(childElem, parent, key); | ||
if (isSugarChildElem) continue; | ||
if (isSugarChildElem) | ||
continue; | ||
assignChild({ | ||
@@ -174,3 +185,4 @@ extend: element[childKey], | ||
const { context } = element; | ||
if (!context || !context.components) return; | ||
if (!context || !context.components) | ||
return; | ||
const { components } = context; | ||
@@ -181,5 +193,6 @@ const { extend } = element; | ||
const componentExists = components[execExtend] || components["smbls." + execExtend]; | ||
if (componentExists) element.extend = componentExists; | ||
if (componentExists) | ||
element.extend = componentExists; | ||
else { | ||
if ((ENV === "test" || ENV === "development") && options.verbose) { | ||
if ((ENV === "testing" || ENV === "development") && options.verbose) { | ||
console.warn(execExtend, "is not in library", components, element); | ||
@@ -193,3 +206,4 @@ console.warn("replacing with ", {}); | ||
const isVariant = (param) => { | ||
if (!(0, import_types.isString)(param)) return; | ||
if (!(0, import_types.isString)(param)) | ||
return; | ||
const firstCharKey = param.slice(0, 1); | ||
@@ -200,3 +214,4 @@ return firstCharKey === "."; | ||
const { props } = element; | ||
if ((0, import_types.isObject)(props) && (0, import_types.isString)(props.variant)) return true; | ||
if ((0, import_types.isObject)(props) && (0, import_types.isString)(props.variant)) | ||
return true; | ||
}; | ||
@@ -210,3 +225,4 @@ const getChildrenComponentsByKey = (key, el) => { | ||
const foundInArray = (0, import_types.isArray)(el.extend) && el.extend.filter((v) => v === key).length; | ||
if (foundString || foundInArray) return el; | ||
if (foundString || foundInArray) | ||
return el; | ||
} | ||
@@ -216,3 +232,4 @@ if (el.parent && el.parent.childExtend) { | ||
const foundInArray = (0, import_types.isArray)(el.parent.childExtend) && el.parent.childExtend.filter((v) => v === key).length; | ||
if (foundString || foundInArray) return el; | ||
if (foundString || foundInArray) | ||
return el; | ||
} | ||
@@ -249,5 +266,7 @@ }; | ||
ref.contentElementKey = contentElementKey || "content"; | ||
} else ref.contentElementKey = "content"; | ||
if (contentElementKey !== "content") opts.contentElementKey = "content"; | ||
} else | ||
ref.contentElementKey = "content"; | ||
if (contentElementKey !== "content") | ||
opts.contentElementKey = "content"; | ||
return ref.contentElementKey; | ||
}; |
@@ -33,3 +33,4 @@ "use strict"; | ||
const setCookie = (cname, cvalue, exdays = 365) => { | ||
if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie)) return; | ||
if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie)) | ||
return; | ||
const d = /* @__PURE__ */ new Date(); | ||
@@ -41,3 +42,4 @@ d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1e3); | ||
const getCookie = (cname) => { | ||
if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie)) return; | ||
if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie)) | ||
return; | ||
const name = `${cname}=`; | ||
@@ -48,4 +50,6 @@ const decodedCookie = decodeURIComponent(import_globals.document.cookie); | ||
let c = ca[i]; | ||
while (c.charAt(0) === " ") c = c.substring(1); | ||
if (c.indexOf(name) === 0) return c.substring(name.length, c.length); | ||
while (c.charAt(0) === " ") | ||
c = c.substring(1); | ||
if (c.indexOf(name) === 0) | ||
return c.substring(name.length, c.length); | ||
} | ||
@@ -55,3 +59,4 @@ return ""; | ||
const removeCookie = (cname) => { | ||
if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie)) return; | ||
if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie)) | ||
return; | ||
import_globals.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; | ||
@@ -58,0 +63,0 @@ }; |
@@ -35,3 +35,4 @@ "use strict"; | ||
timeout = null; | ||
if (!immediate) func.apply(context, args); | ||
if (!immediate) | ||
func.apply(context, args); | ||
}; | ||
@@ -41,3 +42,4 @@ const callNow = immediate && !timeout; | ||
timeout = setTimeout(later, wait); | ||
if (callNow) func.apply(context, args); | ||
if (callNow) | ||
func.apply(context, args); | ||
}; | ||
@@ -44,0 +46,0 @@ } |
@@ -16,16 +16,16 @@ "use strict"; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var index_exports = {}; | ||
module.exports = __toCommonJS(index_exports); | ||
__reExport(index_exports, require("./key.js"), module.exports); | ||
__reExport(index_exports, require("./env.js"), module.exports); | ||
__reExport(index_exports, require("./types.js"), module.exports); | ||
__reExport(index_exports, require("./object.js"), module.exports); | ||
__reExport(index_exports, require("./function.js"), module.exports); | ||
__reExport(index_exports, require("./array.js"), module.exports); | ||
__reExport(index_exports, require("./node.js"), module.exports); | ||
__reExport(index_exports, require("./log.js"), module.exports); | ||
__reExport(index_exports, require("./string.js"), module.exports); | ||
__reExport(index_exports, require("./globals.js"), module.exports); | ||
__reExport(index_exports, require("./cookie.js"), module.exports); | ||
__reExport(index_exports, require("./tags.js"), module.exports); | ||
__reExport(index_exports, require("./component.js"), module.exports); | ||
var utils_exports = {}; | ||
module.exports = __toCommonJS(utils_exports); | ||
__reExport(utils_exports, require("./key.js"), module.exports); | ||
__reExport(utils_exports, require("./env.js"), module.exports); | ||
__reExport(utils_exports, require("./types.js"), module.exports); | ||
__reExport(utils_exports, require("./object.js"), module.exports); | ||
__reExport(utils_exports, require("./function.js"), module.exports); | ||
__reExport(utils_exports, require("./array.js"), module.exports); | ||
__reExport(utils_exports, require("./node.js"), module.exports); | ||
__reExport(utils_exports, require("./log.js"), module.exports); | ||
__reExport(utils_exports, require("./string.js"), module.exports); | ||
__reExport(utils_exports, require("./globals.js"), module.exports); | ||
__reExport(utils_exports, require("./cookie.js"), module.exports); | ||
__reExport(utils_exports, require("./tags.js"), module.exports); | ||
__reExport(utils_exports, require("./component.js"), module.exports); |
@@ -25,3 +25,3 @@ "use strict"; | ||
module.exports = __toCommonJS(key_exports); | ||
const generateKey = /* @__PURE__ */ function() { | ||
const generateKey = function() { | ||
let index = 0; | ||
@@ -28,0 +28,0 @@ function newId() { |
@@ -26,3 +26,4 @@ "use strict"; | ||
const logIf = (bool, ...arg) => { | ||
if (bool) arg.map((v) => console.log(v)); | ||
if (bool) | ||
arg.map((v) => console.log(v)); | ||
}; | ||
@@ -29,0 +30,0 @@ const logGroupIf = (bool, key, ...arg) => { |
@@ -86,3 +86,4 @@ "use strict"; | ||
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, e); | ||
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) continue; | ||
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) | ||
continue; | ||
const elementProp = element[e]; | ||
@@ -99,3 +100,4 @@ const objProp = obj[e]; | ||
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(extend, e); | ||
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) continue; | ||
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) | ||
continue; | ||
const elementProp = element[e]; | ||
@@ -115,3 +117,4 @@ const extendProp = extend[e]; | ||
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop); | ||
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) continue; | ||
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) | ||
continue; | ||
o[prop] = obj[prop]; | ||
@@ -142,6 +145,9 @@ } | ||
for (const key in obj) { | ||
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue; | ||
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, key)) | ||
continue; | ||
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") | ||
continue; | ||
const value = obj[key]; | ||
if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value)) continue; | ||
if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value)) | ||
continue; | ||
if ((0, import_node.isDOMNode)(value)) { | ||
@@ -277,3 +283,4 @@ clone2[key] = value; | ||
const objProp = obj[prop]; | ||
if ((0, import_types.isFunction)(objProp)) continue; | ||
if ((0, import_types.isFunction)(objProp)) | ||
continue; | ||
else if ((0, import_types.isObject)(objProp)) { | ||
@@ -285,3 +292,4 @@ detached[prop] = {}; | ||
objProp.forEach((v, i) => { | ||
if ((0, import_types.isFunction)(v)) return; | ||
if ((0, import_types.isFunction)(v)) | ||
return; | ||
if ((0, import_types.isObject)(v)) { | ||
@@ -301,7 +309,11 @@ detached[prop][i] = {}; | ||
const hasFunction = (str) => { | ||
if (!str) return false; | ||
if (!str) | ||
return false; | ||
const trimmed = str.trim().replace(/\n\s*/g, " ").trim(); | ||
if (trimmed === "") return false; | ||
if (trimmed === "{}") return false; | ||
if (trimmed === "[]") return false; | ||
if (trimmed === "") | ||
return false; | ||
if (trimmed === "{}") | ||
return false; | ||
if (trimmed === "[]") | ||
return false; | ||
const patterns = [ | ||
@@ -324,3 +336,4 @@ /^\(\s*\{[^}]*\}\s*\)\s*=>/, | ||
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop); | ||
if (!hasOwnProperty2) continue; | ||
if (!hasOwnProperty2) | ||
continue; | ||
const objProp = obj[prop]; | ||
@@ -333,3 +346,4 @@ if ((0, import_types.isString)(objProp)) { | ||
} catch (e) { | ||
if (e) destringified[prop] = objProp; | ||
if (e) | ||
destringified[prop] = objProp; | ||
} | ||
@@ -348,3 +362,4 @@ } else { | ||
} catch (e) { | ||
if (e) destringified[prop].push(arrProp); | ||
if (e) | ||
destringified[prop].push(arrProp); | ||
} | ||
@@ -372,3 +387,4 @@ } else { | ||
} catch (e) { | ||
if (opts.verbose) console.warn(e); | ||
if (opts.verbose) | ||
console.warn(e); | ||
} | ||
@@ -378,3 +394,4 @@ }; | ||
for (const e in objToDiff) { | ||
if (e === "ref") continue; | ||
if (e === "ref") | ||
continue; | ||
const originalProp = original[e]; | ||
@@ -422,4 +439,6 @@ const objToDiffProp = objToDiff[e]; | ||
const deepDiff = (lhs, rhs) => { | ||
if (lhs === rhs) return {}; | ||
if (!(0, import_types.isObjectLike)(lhs) || !(0, import_types.isObjectLike)(rhs)) return rhs; | ||
if (lhs === rhs) | ||
return {}; | ||
if (!(0, import_types.isObjectLike)(lhs) || !(0, import_types.isObjectLike)(rhs)) | ||
return rhs; | ||
const deletedValues = Object.keys(lhs).reduce((acc, key) => { | ||
@@ -432,3 +451,4 @@ if (!hasOwnProperty(rhs, key)) { | ||
if ((0, import_types.isDate)(lhs) || (0, import_types.isDate)(rhs)) { | ||
if (lhs.valueOf() === rhs.valueOf()) return {}; | ||
if (lhs.valueOf() === rhs.valueOf()) | ||
return {}; | ||
return rhs; | ||
@@ -455,3 +475,4 @@ } | ||
for (const e in params) { | ||
if (excl.includes(e) || !allowUnderscore && e.startsWith("__")) continue; | ||
if (excl.includes(e) || !allowUnderscore && e.startsWith("__")) | ||
continue; | ||
const elementProp = element[e]; | ||
@@ -473,3 +494,4 @@ const paramsProp = params[e]; | ||
for (const e in params) { | ||
if (excludeFrom.includes(e) || e.startsWith("__")) continue; | ||
if (excludeFrom.includes(e) || e.startsWith("__")) | ||
continue; | ||
obj[e] = params[e]; | ||
@@ -485,7 +507,10 @@ } | ||
} | ||
if (visited.has(obj)) return visited.get(obj); | ||
if (visited.has(obj)) | ||
return visited.get(obj); | ||
visited.set(obj, obj); | ||
for (const e in params) { | ||
if (!Object.hasOwnProperty.call(params, e)) continue; | ||
if (excl.includes(e) || forcedExclude && e.startsWith("__")) continue; | ||
if (!Object.hasOwnProperty.call(params, e)) | ||
continue; | ||
if (excl.includes(e) || forcedExclude && e.startsWith("__")) | ||
continue; | ||
const objProp = obj[e]; | ||
@@ -504,3 +529,4 @@ const paramsProp = params[e]; | ||
const mergeIfExisted = (a, b) => { | ||
if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b)) return deepMerge(a, b); | ||
if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b)) | ||
return deepMerge(a, b); | ||
return a || b; | ||
@@ -512,3 +538,4 @@ }; | ||
const extendOfExtend = objectized[prop]; | ||
if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack); | ||
if (extendOfExtend) | ||
flattenRecursive(extendOfExtend, prop, stack); | ||
delete objectized[prop]; | ||
@@ -544,5 +571,8 @@ return stack; | ||
const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => { | ||
if (obj1 === obj2) return true; | ||
if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2)) return false; | ||
if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2)) return obj1 === obj2; | ||
if (obj1 === obj2) | ||
return true; | ||
if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2)) | ||
return false; | ||
if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2)) | ||
return obj1 === obj2; | ||
const stack = [[obj1, obj2]]; | ||
@@ -552,13 +582,17 @@ const visited = /* @__PURE__ */ new WeakSet(); | ||
const [current1, current2] = stack.pop(); | ||
if (visited.has(current1)) continue; | ||
if (visited.has(current1)) | ||
continue; | ||
visited.add(current1); | ||
const keys1 = Object.keys(current1).filter((key) => !ignoredKeys.includes(key)); | ||
const keys2 = Object.keys(current2).filter((key) => !ignoredKeys.includes(key)); | ||
if (keys1.length !== keys2.length) return false; | ||
if (keys1.length !== keys2.length) | ||
return false; | ||
for (const key of keys1) { | ||
if (!Object.prototype.hasOwnProperty.call(current2, key)) return false; | ||
if (!Object.prototype.hasOwnProperty.call(current2, key)) | ||
return false; | ||
const value1 = current1[key]; | ||
const value2 = current2[key]; | ||
if ((0, import_node.isDOMNode)(value1) || (0, import_node.isDOMNode)(value2)) { | ||
if (value1 !== value2) return false; | ||
if (value1 !== value2) | ||
return false; | ||
} else if ((0, import_types.isObjectLike)(value1) && (0, import_types.isObjectLike)(value2)) { | ||
@@ -576,3 +610,4 @@ if (value1 !== value2) { | ||
const removeFromObject = (obj, props) => { | ||
if (props === void 0 || props === null) return obj; | ||
if (props === void 0 || props === null) | ||
return obj; | ||
if ((0, import_types.is)(props)("string", "number")) { | ||
@@ -674,3 +709,3 @@ delete obj[props]; | ||
if (repeatCount >= maxRepeats * 2) { | ||
if (ENV === "test" || ENV === "development") { | ||
if (ENV === "testing" || ENV === "development") { | ||
console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern); | ||
@@ -677,0 +712,0 @@ } |
@@ -50,3 +50,4 @@ "use strict"; | ||
function replaceLiteralsWithObjectFields(str, options = {}, forcedState) { | ||
if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{")) return str; | ||
if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{")) | ||
return str; | ||
const reg = brackRegex[options.bracketsLength || 2]; | ||
@@ -53,0 +54,0 @@ const obj = forcedState || (this == null ? void 0 : this.state) || {}; |
@@ -39,3 +39,4 @@ "use strict"; | ||
const isObject = (arg) => { | ||
if (arg === null) return false; | ||
if (arg === null) | ||
return false; | ||
return typeof arg === "object" && arg.constructor === Object; | ||
@@ -51,3 +52,4 @@ }; | ||
const isObjectLike = (arg) => { | ||
if (arg === null) return false; | ||
if (arg === null) | ||
return false; | ||
return typeof arg === "object"; | ||
@@ -54,0 +56,0 @@ }; |
@@ -12,3 +12,4 @@ import { deepClone, deepMerge } from "./object.js"; | ||
const removeFromArray = (arr, index) => { | ||
if (isString(index)) index = parseInt(index); | ||
if (isString(index)) | ||
index = parseInt(index); | ||
if (isNumber(index)) { | ||
@@ -46,3 +47,4 @@ if (index < 0 || index >= arr.length || isNaN(index)) { | ||
const cutArrayAfterValue = (arr, value) => { | ||
if (!isArray(arr)) return; | ||
if (!isArray(arr)) | ||
return; | ||
const index = arr.indexOf(value); | ||
@@ -106,3 +108,4 @@ if (index !== -1) { | ||
const checkIfStringIsInArray = (string, arr) => { | ||
if (!string) return; | ||
if (!string) | ||
return; | ||
return arr.filter((v) => string.includes(v)).length; | ||
@@ -109,0 +112,0 @@ }; |
@@ -26,3 +26,4 @@ var __defProp = Object.defineProperty; | ||
const isFirstKeyString = isString(key); | ||
if (!isFirstKeyString) return; | ||
if (!isFirstKeyString) | ||
return; | ||
const firstCharKey = key.slice(0, 1); | ||
@@ -33,3 +34,4 @@ return /^[A-Z]*$/.test(firstCharKey); | ||
const isFirstKeyString = isString(key); | ||
if (!isFirstKeyString) return; | ||
if (!isFirstKeyString) | ||
return; | ||
const firstCharKey = key.slice(0, 1); | ||
@@ -39,3 +41,4 @@ return /^[a-z]*$/.test(firstCharKey); | ||
const addAdditionalExtend = (newExtend, element) => { | ||
if (!newExtend) return element; | ||
if (!newExtend) | ||
return element; | ||
const { extend: elementExtend } = element; | ||
@@ -65,3 +68,4 @@ const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend]; | ||
const logErr = (_a = parent || element) == null ? void 0 : _a.error; | ||
if (logErr) logErr.call(element, "Sugar component includes params for builtin components", { verbose: true }); | ||
if (logErr) | ||
logErr.call(element, "Sugar component includes params for builtin components", { verbose: true }); | ||
} | ||
@@ -79,3 +83,4 @@ return !hasComponentAttrs || childProps || extendProps || children || childExtends; | ||
const isExtendKeyComponent = context && context.components[extendFromKey]; | ||
if (element === isExtendKeyComponent) return element; | ||
if (element === isExtendKeyComponent) | ||
return element; | ||
else if (isSugar) { | ||
@@ -103,3 +108,4 @@ const newElem = addAdditionalExtend(element.extends, { | ||
} | ||
if (childExtends) newElem.childExtend = childExtends; | ||
if (childExtends) | ||
newElem.childExtend = childExtends; | ||
return newElem; | ||
@@ -126,3 +132,4 @@ } else if (!extend || extend === true) { | ||
const childElems = getCapitalCaseKeys(element.props); | ||
if (!childElems.length) return element; | ||
if (!childElems.length) | ||
return element; | ||
for (const i in childElems) { | ||
@@ -136,8 +143,12 @@ const childKey = childElems[i]; | ||
}; | ||
if (newChild == null ? void 0 : newChild.ignoreExtend) continue; | ||
if (newChild === null) assignChild(null); | ||
else if (!childElem) assignChild(deepClone(newChild)); | ||
if (newChild == null ? void 0 : newChild.ignoreExtend) | ||
continue; | ||
if (newChild === null) | ||
assignChild(null); | ||
else if (!childElem) | ||
assignChild(deepClone(newChild)); | ||
else { | ||
const isSugarChildElem = checkIfSugar(childElem, parent, key); | ||
if (isSugarChildElem) continue; | ||
if (isSugarChildElem) | ||
continue; | ||
assignChild({ | ||
@@ -155,3 +166,4 @@ extend: element[childKey], | ||
const { context } = element; | ||
if (!context || !context.components) return; | ||
if (!context || !context.components) | ||
return; | ||
const { components } = context; | ||
@@ -162,5 +174,6 @@ const { extend } = element; | ||
const componentExists = components[execExtend] || components["smbls." + execExtend]; | ||
if (componentExists) element.extend = componentExists; | ||
if (componentExists) | ||
element.extend = componentExists; | ||
else { | ||
if ((ENV === "test" || ENV === "development") && options.verbose) { | ||
if ((ENV === "testing" || ENV === "development") && options.verbose) { | ||
console.warn(execExtend, "is not in library", components, element); | ||
@@ -174,3 +187,4 @@ console.warn("replacing with ", {}); | ||
const isVariant = (param) => { | ||
if (!isString(param)) return; | ||
if (!isString(param)) | ||
return; | ||
const firstCharKey = param.slice(0, 1); | ||
@@ -181,3 +195,4 @@ return firstCharKey === "."; | ||
const { props } = element; | ||
if (isObject(props) && isString(props.variant)) return true; | ||
if (isObject(props) && isString(props.variant)) | ||
return true; | ||
}; | ||
@@ -191,3 +206,4 @@ const getChildrenComponentsByKey = (key, el) => { | ||
const foundInArray = isArray(el.extend) && el.extend.filter((v) => v === key).length; | ||
if (foundString || foundInArray) return el; | ||
if (foundString || foundInArray) | ||
return el; | ||
} | ||
@@ -197,3 +213,4 @@ if (el.parent && el.parent.childExtend) { | ||
const foundInArray = isArray(el.parent.childExtend) && el.parent.childExtend.filter((v) => v === key).length; | ||
if (foundString || foundInArray) return el; | ||
if (foundString || foundInArray) | ||
return el; | ||
} | ||
@@ -230,4 +247,6 @@ }; | ||
ref.contentElementKey = contentElementKey || "content"; | ||
} else ref.contentElementKey = "content"; | ||
if (contentElementKey !== "content") opts.contentElementKey = "content"; | ||
} else | ||
ref.contentElementKey = "content"; | ||
if (contentElementKey !== "content") | ||
opts.contentElementKey = "content"; | ||
return ref.contentElementKey; | ||
@@ -234,0 +253,0 @@ }; |
@@ -5,3 +5,4 @@ import { isUndefined } from "./types.js"; | ||
const setCookie = (cname, cvalue, exdays = 365) => { | ||
if (isUndefined(document) || isUndefined(document.cookie)) return; | ||
if (isUndefined(document) || isUndefined(document.cookie)) | ||
return; | ||
const d = /* @__PURE__ */ new Date(); | ||
@@ -13,3 +14,4 @@ d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1e3); | ||
const getCookie = (cname) => { | ||
if (isUndefined(document) || isUndefined(document.cookie)) return; | ||
if (isUndefined(document) || isUndefined(document.cookie)) | ||
return; | ||
const name = `${cname}=`; | ||
@@ -20,4 +22,6 @@ const decodedCookie = decodeURIComponent(document.cookie); | ||
let c = ca[i]; | ||
while (c.charAt(0) === " ") c = c.substring(1); | ||
if (c.indexOf(name) === 0) return c.substring(name.length, c.length); | ||
while (c.charAt(0) === " ") | ||
c = c.substring(1); | ||
if (c.indexOf(name) === 0) | ||
return c.substring(name.length, c.length); | ||
} | ||
@@ -27,3 +31,4 @@ return ""; | ||
const removeCookie = (cname) => { | ||
if (isUndefined(document) || isUndefined(document.cookie)) return; | ||
if (isUndefined(document) || isUndefined(document.cookie)) | ||
return; | ||
document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; | ||
@@ -30,0 +35,0 @@ }; |
@@ -8,3 +8,4 @@ function debounce(func, wait, immediate) { | ||
timeout = null; | ||
if (!immediate) func.apply(context, args); | ||
if (!immediate) | ||
func.apply(context, args); | ||
}; | ||
@@ -14,3 +15,4 @@ const callNow = immediate && !timeout; | ||
timeout = setTimeout(later, wait); | ||
if (callNow) func.apply(context, args); | ||
if (callNow) | ||
func.apply(context, args); | ||
}; | ||
@@ -17,0 +19,0 @@ } |
@@ -1,2 +0,2 @@ | ||
const generateKey = /* @__PURE__ */ function() { | ||
const generateKey = function() { | ||
let index = 0; | ||
@@ -3,0 +3,0 @@ function newId() { |
const logIf = (bool, ...arg) => { | ||
if (bool) arg.map((v) => console.log(v)); | ||
if (bool) | ||
arg.map((v) => console.log(v)); | ||
}; | ||
@@ -4,0 +5,0 @@ const logGroupIf = (bool, key, ...arg) => { |
@@ -55,3 +55,4 @@ var __defProp = Object.defineProperty; | ||
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, e); | ||
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) continue; | ||
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) | ||
continue; | ||
const elementProp = element[e]; | ||
@@ -68,3 +69,4 @@ const objProp = obj[e]; | ||
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(extend, e); | ||
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) continue; | ||
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) | ||
continue; | ||
const elementProp = element[e]; | ||
@@ -84,3 +86,4 @@ const extendProp = extend[e]; | ||
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop); | ||
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) continue; | ||
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) | ||
continue; | ||
o[prop] = obj[prop]; | ||
@@ -111,6 +114,9 @@ } | ||
for (const key in obj) { | ||
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue; | ||
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, key)) | ||
continue; | ||
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") | ||
continue; | ||
const value = obj[key]; | ||
if (cleanUndefined && isUndefined(value) || cleanNull && isNull(value)) continue; | ||
if (cleanUndefined && isUndefined(value) || cleanNull && isNull(value)) | ||
continue; | ||
if (isDOMNode(value)) { | ||
@@ -245,3 +251,4 @@ clone2[key] = value; | ||
const objProp = obj[prop]; | ||
if (isFunction(objProp)) continue; | ||
if (isFunction(objProp)) | ||
continue; | ||
else if (isObject(objProp)) { | ||
@@ -253,3 +260,4 @@ detached[prop] = {}; | ||
objProp.forEach((v, i) => { | ||
if (isFunction(v)) return; | ||
if (isFunction(v)) | ||
return; | ||
if (isObject(v)) { | ||
@@ -269,7 +277,11 @@ detached[prop][i] = {}; | ||
const hasFunction = (str) => { | ||
if (!str) return false; | ||
if (!str) | ||
return false; | ||
const trimmed = str.trim().replace(/\n\s*/g, " ").trim(); | ||
if (trimmed === "") return false; | ||
if (trimmed === "{}") return false; | ||
if (trimmed === "[]") return false; | ||
if (trimmed === "") | ||
return false; | ||
if (trimmed === "{}") | ||
return false; | ||
if (trimmed === "[]") | ||
return false; | ||
const patterns = [ | ||
@@ -292,3 +304,4 @@ /^\(\s*\{[^}]*\}\s*\)\s*=>/, | ||
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop); | ||
if (!hasOwnProperty2) continue; | ||
if (!hasOwnProperty2) | ||
continue; | ||
const objProp = obj[prop]; | ||
@@ -301,3 +314,4 @@ if (isString(objProp)) { | ||
} catch (e) { | ||
if (e) destringified[prop] = objProp; | ||
if (e) | ||
destringified[prop] = objProp; | ||
} | ||
@@ -316,3 +330,4 @@ } else { | ||
} catch (e) { | ||
if (e) destringified[prop].push(arrProp); | ||
if (e) | ||
destringified[prop].push(arrProp); | ||
} | ||
@@ -340,3 +355,4 @@ } else { | ||
} catch (e) { | ||
if (opts.verbose) console.warn(e); | ||
if (opts.verbose) | ||
console.warn(e); | ||
} | ||
@@ -346,3 +362,4 @@ }; | ||
for (const e in objToDiff) { | ||
if (e === "ref") continue; | ||
if (e === "ref") | ||
continue; | ||
const originalProp = original[e]; | ||
@@ -390,4 +407,6 @@ const objToDiffProp = objToDiff[e]; | ||
const deepDiff = (lhs, rhs) => { | ||
if (lhs === rhs) return {}; | ||
if (!isObjectLike(lhs) || !isObjectLike(rhs)) return rhs; | ||
if (lhs === rhs) | ||
return {}; | ||
if (!isObjectLike(lhs) || !isObjectLike(rhs)) | ||
return rhs; | ||
const deletedValues = Object.keys(lhs).reduce((acc, key) => { | ||
@@ -400,3 +419,4 @@ if (!hasOwnProperty(rhs, key)) { | ||
if (isDate(lhs) || isDate(rhs)) { | ||
if (lhs.valueOf() === rhs.valueOf()) return {}; | ||
if (lhs.valueOf() === rhs.valueOf()) | ||
return {}; | ||
return rhs; | ||
@@ -423,3 +443,4 @@ } | ||
for (const e in params) { | ||
if (excl.includes(e) || !allowUnderscore && e.startsWith("__")) continue; | ||
if (excl.includes(e) || !allowUnderscore && e.startsWith("__")) | ||
continue; | ||
const elementProp = element[e]; | ||
@@ -441,3 +462,4 @@ const paramsProp = params[e]; | ||
for (const e in params) { | ||
if (excludeFrom.includes(e) || e.startsWith("__")) continue; | ||
if (excludeFrom.includes(e) || e.startsWith("__")) | ||
continue; | ||
obj[e] = params[e]; | ||
@@ -453,7 +475,10 @@ } | ||
} | ||
if (visited.has(obj)) return visited.get(obj); | ||
if (visited.has(obj)) | ||
return visited.get(obj); | ||
visited.set(obj, obj); | ||
for (const e in params) { | ||
if (!Object.hasOwnProperty.call(params, e)) continue; | ||
if (excl.includes(e) || forcedExclude && e.startsWith("__")) continue; | ||
if (!Object.hasOwnProperty.call(params, e)) | ||
continue; | ||
if (excl.includes(e) || forcedExclude && e.startsWith("__")) | ||
continue; | ||
const objProp = obj[e]; | ||
@@ -472,3 +497,4 @@ const paramsProp = params[e]; | ||
const mergeIfExisted = (a, b) => { | ||
if (isObjectLike(a) && isObjectLike(b)) return deepMerge(a, b); | ||
if (isObjectLike(a) && isObjectLike(b)) | ||
return deepMerge(a, b); | ||
return a || b; | ||
@@ -480,3 +506,4 @@ }; | ||
const extendOfExtend = objectized[prop]; | ||
if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack); | ||
if (extendOfExtend) | ||
flattenRecursive(extendOfExtend, prop, stack); | ||
delete objectized[prop]; | ||
@@ -512,5 +539,8 @@ return stack; | ||
const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => { | ||
if (obj1 === obj2) return true; | ||
if (!isObjectLike(obj1) || !isObjectLike(obj2)) return false; | ||
if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2; | ||
if (obj1 === obj2) | ||
return true; | ||
if (!isObjectLike(obj1) || !isObjectLike(obj2)) | ||
return false; | ||
if (isDOMNode(obj1) || isDOMNode(obj2)) | ||
return obj1 === obj2; | ||
const stack = [[obj1, obj2]]; | ||
@@ -520,13 +550,17 @@ const visited = /* @__PURE__ */ new WeakSet(); | ||
const [current1, current2] = stack.pop(); | ||
if (visited.has(current1)) continue; | ||
if (visited.has(current1)) | ||
continue; | ||
visited.add(current1); | ||
const keys1 = Object.keys(current1).filter((key) => !ignoredKeys.includes(key)); | ||
const keys2 = Object.keys(current2).filter((key) => !ignoredKeys.includes(key)); | ||
if (keys1.length !== keys2.length) return false; | ||
if (keys1.length !== keys2.length) | ||
return false; | ||
for (const key of keys1) { | ||
if (!Object.prototype.hasOwnProperty.call(current2, key)) return false; | ||
if (!Object.prototype.hasOwnProperty.call(current2, key)) | ||
return false; | ||
const value1 = current1[key]; | ||
const value2 = current2[key]; | ||
if (isDOMNode(value1) || isDOMNode(value2)) { | ||
if (value1 !== value2) return false; | ||
if (value1 !== value2) | ||
return false; | ||
} else if (isObjectLike(value1) && isObjectLike(value2)) { | ||
@@ -544,3 +578,4 @@ if (value1 !== value2) { | ||
const removeFromObject = (obj, props) => { | ||
if (props === void 0 || props === null) return obj; | ||
if (props === void 0 || props === null) | ||
return obj; | ||
if (is(props)("string", "number")) { | ||
@@ -642,3 +677,3 @@ delete obj[props]; | ||
if (repeatCount >= maxRepeats * 2) { | ||
if (ENV === "test" || ENV === "development") { | ||
if (ENV === "testing" || ENV === "development") { | ||
console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern); | ||
@@ -645,0 +680,0 @@ } |
@@ -18,3 +18,4 @@ const stringIncludesAny = (str, characters) => { | ||
function replaceLiteralsWithObjectFields(str, options = {}, forcedState) { | ||
if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{")) return str; | ||
if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{")) | ||
return str; | ||
const reg = brackRegex[options.bracketsLength || 2]; | ||
@@ -21,0 +22,0 @@ const obj = forcedState || (this == null ? void 0 : this.state) || {}; |
import { isHtmlElement, isNode } from "./node.js"; | ||
const isObject = (arg) => { | ||
if (arg === null) return false; | ||
if (arg === null) | ||
return false; | ||
return typeof arg === "object" && arg.constructor === Object; | ||
@@ -14,3 +15,4 @@ }; | ||
const isObjectLike = (arg) => { | ||
if (arg === null) return false; | ||
if (arg === null) | ||
return false; | ||
return typeof arg === "object"; | ||
@@ -17,0 +19,0 @@ }; |
@@ -818,3 +818,3 @@ 'use strict' | ||
if (repeatCount >= maxRepeats * 2) { | ||
if (ENV === 'test' || ENV === 'development') { | ||
if (ENV === 'testing' || ENV === 'development') { | ||
console.warn('Warning: Potential infinite loop detected due to repeated sequence:', pattern) | ||
@@ -821,0 +821,0 @@ } |
{ | ||
"name": "@domql/utils", | ||
"version": "2.5.200", | ||
"version": "2.5.203", | ||
"license": "MIT", | ||
@@ -24,6 +24,6 @@ "type": "module", | ||
"build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs", | ||
"build": "rimraf -I dist; npm run build:cjs; npm run build:esm", | ||
"build": "npx rimraf -I dist; npm run build:cjs; npm run build:esm", | ||
"prepublish": "npm run build; npm run copy:package:cjs" | ||
}, | ||
"gitHead": "0afb63ec375f0526f47ff300885de393138b01e8", | ||
"gitHead": "f8c712416647ab3789253b7176eaa762627fc677", | ||
"devDependencies": { | ||
@@ -30,0 +30,0 @@ "@babel/core": "^7.12.0" |
160252
0.46%5112
2.73%