@symbo.ls/utils 3.14.10 → 3.14.12
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/CHANGELOG.md +16 -0
- package/array.js +162 -0
- package/assets.js +117 -0
- package/browser.js +13 -0
- package/cache.js +7 -0
- package/cdn.js +83 -0
- package/component.js +25 -0
- package/cookie.js +78 -0
- package/date.js +10 -0
- package/detectHeight.js +42 -0
- package/dist/cjs/object.js +6 -6
- package/dist/esm/object.js +6 -6
- package/element.js +148 -0
- package/env.js +15 -0
- package/events.js +19 -0
- package/extends.js +519 -0
- package/fibonacci.js +9 -0
- package/files.js +3 -0
- package/function.js +145 -0
- package/globals.js +8 -0
- package/if.js +30 -0
- package/index.js +44 -0
- package/key.js +20 -0
- package/keys.js +176 -0
- package/load.js +236 -0
- package/log.js +12 -0
- package/metadata.js +392 -0
- package/methods.js +684 -0
- package/node.js +37 -0
- package/object.js +859 -0
- package/package.json +3 -2
- package/projectKeys.js +30 -0
- package/props.js +327 -0
- package/scaling.js +15 -0
- package/scope.js +32 -0
- package/sharedLibraries.js +184 -0
- package/state.js +203 -0
- package/string-extra.js +69 -0
- package/string.js +206 -0
- package/style.js +23 -0
- package/tags.js +176 -0
- package/triggerEvent.js +102 -0
- package/types.js +55 -0
- package/update.js +27 -0
package/dist/esm/object.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import{window as
|
|
1
|
+
import{window as _}from"./globals.js";import{isFunction as S,isObjectLike as u,isObject as d,isArray as w,isString as g,is as D}from"./types.js";import{unstackArrayOfObjects as C}from"./array.js";import{stringIncludesAny as T}from"./string.js";import{isDOMNode as h}from"./node.js";import{METHODS_EXL as W}from"./keys.js";const k="production",O=e=>e.charCodeAt(0)===95&&e.charCodeAt(1)===95,$=(e,t,o,r)=>{if(S(e))return t?typeof e.call!="function"?e:e.call(t,t,o||t.state,r||t.context):void 0;if(e!=null&&t?.context?.plugins&&(w(e)||d(e)&&!h(e))){const n=t.context.plugins;for(const s of n)if(s.resolveHandler){const c=s.resolveHandler(e,t);if(typeof c=="function")return $(c,t,o,r)}}return e},Y=(e,t,o)=>{for(const r in t)e[r]=$(t[r],o)},m=(e,t,o=[])=>{const r=o instanceof Set;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(O(n)||(r?o.has(n):o.includes(n))||e[n]===void 0&&(e[n]=t[n]));return e},b=(e,t,o=W)=>A(e,t,o,null),A=(e,t,o,r)=>{if(e===t)return e;if(r){for(let s=0;s<r.length;s+=2)if(r[s]===e&&r[s+1]===t)return e}const n=o instanceof Set;for(const s in t){if(!Object.prototype.hasOwnProperty.call(t,s)||O(s)||s==="constructor"||s==="prototype"||(n?o.has(s):o.includes(s)))continue;const c=e[s],i=t[s];if(u(c)&&u(i)){const l=r||[];l.push(e,t),A(c,i,o,l),l.length-=2}else c===void 0&&(e[s]=i)}return e},j=(e,t=[])=>{const o=t instanceof Set,r={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(O(n)||(o?t.has(n):t.includes(n))||(r[n]=e[n]));return r},I=(e,t={})=>{const{exclude:o=[],cleanUndefined:r=!1,cleanNull:n=!1,window:s,visited:c=new WeakMap,handleExtends:i=!1}=t,l=s||_||globalThis;if(!u(e)||h(e))return e;if(c.has(e))return c.get(e);const a=w(e)?[]:{};c.set(e,a);const x=o instanceof Set?o:o.length>3?new Set(o):null;for(const p in e){if(!Object.prototype.hasOwnProperty.call(e,p)||O(p)||p==="__proto__"||(x?x.has(p):o.includes(p)))continue;const y=e[p];if(!(r&&y===void 0)&&!(n&&y===null)){if(h(y)){a[p]=y;continue}if(i&&p==="extends"&&w(y)){a[p]=C(y,o);continue}if(S(y)){a[p]=y;continue}u(y)?a[p]=I(y,{...t,visited:c}):a[p]=y}}return a},E=(e,t={})=>{(e.node||e.__ref||e.parent||e.__element||e.parse)&&((e.__element||e.parent?.__element).warn("Trying to clone element or state at",e),e=e.parse?.());for(const o in e){const r=e[o];if(S(r))t[o]=r.toString();else if(d(r))t[o]={},E(r,t[o]);else if(w(r)){const n=t[o]=[];for(let s=0;s<r.length;s++){const c=r[s];d(c)?(n[s]={},E(c,n[s])):S(c)?n[s]=c.toString():n[s]=c}}else t[o]=r}return t},R=new Set(["&","*","-",":","%","{","}",">","<","@",".","/","!"," "]),v=(e={},t=0)=>{if(e===null||typeof e!="object")return String(e);let o=!1;for(const s in e){o=!0;break}if(!o)return"{}";const r=" ".repeat(t);let n=`{
|
|
2
2
|
`;for(const s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;const c=e[s];let i=!1;for(let f=0;f<s.length;f++)if(R.has(s[f])){i=!0;break}const l=i?`'${s}'`:s;if(n+=`${r} ${l}: `,w(c)){n+=`[
|
|
3
|
-
`;for(const f of c)u(f)&&f!==null?n+=`${r} ${
|
|
3
|
+
`;for(const f of c)u(f)&&f!==null?n+=`${r} ${v(f,t+2)},
|
|
4
4
|
`:g(f)?n+=`${r} '${f}',
|
|
5
5
|
`:n+=`${r} ${f},
|
|
6
|
-
`;n+=`${r} ]`}else u(c)?n+=
|
|
6
|
+
`;n+=`${r} ]`}else u(c)?n+=v(c,t+1):g(c)?n+=T(c,[`
|
|
7
7
|
`,"'"])?`\`${c}\``:`'${c}'`:n+=c;n+=`,
|
|
8
8
|
`}return n+=`${r}}`,n},M=[/^\(\s*\{[^}]*\}\s*\)\s*=>/,/^(\([^)]*\)|[^=]*)\s*=>/,/^function[\s(]/,/^async\s+/,/^\(\s*function/,/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/],F=/^["[{]/,P=e=>{if(!e)return!1;const t=e.trim().replace(/\n\s*/g," ").trim();if(t===""||t==="{}"||t==="[]"||!M.some(s=>s.test(t)))return!1;const r=t.charCodeAt(0),n=t.includes("=>");return!(r===123&&!n||r===91||F.test(t)&&!n)},L=e=>(0,eval)(e),N=(e,t={},o={window:{eval:L}})=>{for(const r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;const n=e[r];if(g(n))if(P(n))try{t[r]=o.window.eval(`(${n})`)}catch(s){typeof console<"u"&&console.warn&&console.warn('[smbls] deepDestringifyFunctions: eval failed on "'+r+'" \u2014 function will be left as a string and el.call("'+r+'") will silently no-op. Reason: '+(s&&s.message?s.message:String(s))+`.
|
|
9
9
|
First 200 chars of source: `+String(n).slice(0,200)),t[r]=n}else t[r]=n;else if(w(n)){const s=t[r]=[];for(let c=0;c<n.length;c++){const i=n[c];if(g(i))if(P(i))try{s.push(o.window.eval(`(${i})`))}catch(l){typeof console<"u"&&console.warn&&console.warn(`[smbls] deepDestringifyFunctions: eval failed in array at index ${c} (prop "${r}"). Reason: ${l&&l.message?l.message:String(l)}.
|
|
10
|
-
First 200 chars: ${String(i).slice(0,200)}`),s.push(i)}else s.push(i);else d(i)?s.push(N(i)):s.push(i)}}else d(n)?t[r]=N(n,t[r]):t[r]=n}return t},
|
|
11
|
-
`);t[r]=
|
|
12
|
-
return (${n}); })`)(t)}catch{try{t[r]=
|
|
10
|
+
First 200 chars: ${String(i).slice(0,200)}`),s.push(i)}else s.push(i);else d(i)?s.push(N(i)):s.push(i)}}else d(n)?t[r]=N(n,t[r]):t[r]=n}return t},B=e=>!e||typeof e!="object"?e:e.__type==="Set"&&Array.isArray(e.values)?new Set(e.values):e.__type==="Map"&&Array.isArray(e.entries)?new Map(e.entries):e,ee=e=>{if(!e||typeof e!="object")return e;const t={},o=[];for(const r of Object.keys(e)){const n=e[r];g(n)&&P(n)?o.push([r,n]):t[r]=B(n)}for(const[r,n]of o)try{const s=Object.keys(t).map(c=>`var ${c} = __gs__[${JSON.stringify(c)}];`).join(`
|
|
11
|
+
`);t[r]=_.eval(`(function(__gs__) { ${s}
|
|
12
|
+
return (${n}); })`)(t)}catch{try{t[r]=_.eval(`(${n})`)}catch{t[r]=n}}return t},te=(e,t={verbose:!0})=>{try{return e?_.eval("("+e+")"):{}}catch(o){t.verbose&&console.warn(o)}},ne=(e,...t)=>Object.prototype.hasOwnProperty.call(e,...t),H=e=>{for(const t in e)return!1;return!0},re=e=>d(e)&&H(e),oe=()=>Object.create(null),se=(e,t,o={})=>{const r=o.exclude||[],n=o.preventUnderscore;for(const s in t)r.includes(s)||!n&&O(s)||s==="constructor"||s==="prototype"||t[s]!==void 0&&(e[s]=t[s]);return e},ce=(e,t,o=[])=>{const r=o instanceof Set;for(const n in t)O(n)||n==="constructor"||n==="prototype"||(r?o.has(n):o.includes(n))||(e[n]=t[n]);return e},J=(e,t,o={},r=new WeakMap)=>{if(!u(e)||!u(t)||h(e)||h(t))return t;if(r.has(e))return r.get(e);r.set(e,e);const n=o.exclude,s=n?n instanceof Set?n:new Set(n):null,c=!o.preventForce;for(const i in t){if(!Object.prototype.hasOwnProperty.call(t,i)||s&&s.has(i)||c&&O(i)||i==="constructor"||i==="prototype")continue;const l=e[i],f=t[i];h(f)?e[i]=f:u(l)&&u(f)?e[i]=J(l,f,o,r):f!==void 0&&(e[i]=f)}return e},V=(e,t,o=new Set)=>{if(typeof e!="object"||typeof t!="object"||e===null||t===null)return e===t;if(o.has(e)||o.has(t))return!0;o.add(e),o.add(t);const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(let s=0;s<r.length;s++){const c=r[s];if(!Object.prototype.hasOwnProperty.call(t,c)||!V(e[c],t[c],o))return!1}return!0},q=new Set(["node","__ref"]),ie=(e,t,o=q)=>{if(e===t)return!0;if(!u(e)||!u(t)||h(e)||h(t))return e===t;const r=o instanceof Set?o:new Set(o),n=new WeakSet;function s(c,i){if(n.has(i))return!0;n.add(i);for(const l in i){if(!Object.prototype.hasOwnProperty.call(i,l)||r.has(l))continue;if(!Object.prototype.hasOwnProperty.call(c,l))return!1;const f=i[l],a=c[l];if(h(f)||h(a)){if(f!==a)return!1}else if(u(f)&&u(a)){if(!s(a,f))return!1}else if(f!==a)return!1}return!0}return s(e,t)},fe=(e,t)=>{if(t==null)return e;if(D(t)("string","number"))delete e[t];else if(w(t))for(let o=0;o<t.length;o++)delete e[t[o]];else throw new Error("Invalid input: props must be a string or an array of strings");return e},z=e=>{if(e===null||typeof e!="object")return e;const t=Object.create(null);for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=z(e[o]));return t},le=(e,t)=>{if(e.length===0)return t;const o={};let r=o;for(let n=0;n<e.length;n++)n===e.length-1&&t?r[e[n]]=t:(r[e[n]]={},r=r[e[n]]);return o},ue=(e,t)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let o=e;for(let n=0;n<t.length-1;n++){if(o[t[n]]===void 0)return;o=o[t[n]]}const r=t[t.length-1];o&&Object.prototype.hasOwnProperty.call(o,r)&&delete o[r]},ae=(e,t,o)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let r=e;for(let n=0;n<t.length-1;n++)(!r[t[n]]||typeof r[t[n]]!="object")&&(r[t[n]]={}),r=r[t[n]];return r[t[t.length-1]]=o,e},pe=(e,t)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let o=e;for(let r=0;r<t.length;r++){if(o==null)return;o=o[t[r]]}return o},ye=e=>{let o=[],r=0;for(let n=0;n<e.length;n++)if(o.length<2)o.push(e[n]);else if(e[n]===o[n%2]?r++:(o=[e[n-1],e[n]],r=1),r>=20)return(k==="test"||k==="development")&&console.warn("Warning: Potential infinite loop detected due to repeated sequence:",o),!0},he=e=>{const t=new WeakSet;function o(r){if(r&&typeof r=="object"){if(t.has(r))return!0;t.add(r);for(const n in r)if(Object.prototype.hasOwnProperty.call(r,n)&&o(r[n]))return console.log(r,"cycle at "+n),!0}return!1}return o(e)},we=(e,t)=>{const o=t instanceof Set?t:new Set(t),r={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&!o.has(n)&&(r[n]=e[n]);return r};export{j as clone,le as createNestedObject,z as createObjectWithoutPrototype,I as deepClone,ie as deepContains,N as deepDestringifyFunctions,b as deepMerge,E as deepStringifyFunctions,ee as destringifyGlobalScope,ye as detectInfiniteLoop,we as excludeKeysFromObject,$ as exec,pe as getInObjectByPath,P as hasFunction,ne as hasOwnProperty,he as isCyclic,H as isEmpty,re as isEmptyObject,V as isEqualDeep,oe as makeObjectWithoutPrototype,Y as map,m as merge,v as objectToString,se as overwrite,J as overwriteDeep,ce as overwriteShallow,fe as removeFromObject,ue as removeNestedKeyByPath,ae as setInObjectByPath,te as stringToObject};
|
package/element.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { createExtends } from './extends.js'
|
|
4
|
+
import { createKey } from './key.js'
|
|
5
|
+
import { isNode } from './node.js'
|
|
6
|
+
import { createProps } from './props.js'
|
|
7
|
+
import { HTML_TAGS } from './tags.js'
|
|
8
|
+
import { is, isFunction } from './types.js'
|
|
9
|
+
|
|
10
|
+
const ENV = process.env.NODE_ENV
|
|
11
|
+
|
|
12
|
+
export const returnValueAsText = (element, parent, key) => {
|
|
13
|
+
const childExtendsTag = parent.childExtends && parent.childExtends.tag
|
|
14
|
+
const childPropsTag = parent.childProps && parent.childProps.tag
|
|
15
|
+
const isKeyValidHTMLTag = HTML_TAGS.body.has(key) && key
|
|
16
|
+
return {
|
|
17
|
+
text: element,
|
|
18
|
+
tag: childExtendsTag || childPropsTag || isKeyValidHTMLTag || 'string'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const createBasedOnType = (element, parent, key) => {
|
|
23
|
+
// if ELEMENT is not given
|
|
24
|
+
if (element === undefined) {
|
|
25
|
+
if (ENV === 'test' || ENV === 'development') {
|
|
26
|
+
console.warn(
|
|
27
|
+
key,
|
|
28
|
+
'element is undefined in',
|
|
29
|
+
parent?.__ref?.path
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
return {}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (element === null) return
|
|
36
|
+
if (element === true) return {}
|
|
37
|
+
|
|
38
|
+
if (is(element)('string', 'number')) {
|
|
39
|
+
return returnValueAsText(element, parent, key)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (isFunction(element)) {
|
|
43
|
+
return { props: element }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return element
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const addRef = (element, parent) => {
|
|
50
|
+
const ref = {}
|
|
51
|
+
ref.origin = element
|
|
52
|
+
ref.parent = parent
|
|
53
|
+
return ref
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const createParent = (element, parent, key, options, root) => {
|
|
57
|
+
if (!parent) return root
|
|
58
|
+
if (isNode(parent)) {
|
|
59
|
+
const parentNodeWrapper = { key: ':root', node: parent }
|
|
60
|
+
root[`${key}_parent`] = parentNodeWrapper
|
|
61
|
+
return parentNodeWrapper
|
|
62
|
+
}
|
|
63
|
+
return parent
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const createRoot = (element, parent) => {
|
|
67
|
+
const { __ref: ref } = element
|
|
68
|
+
const { __ref: parentRef } = parent
|
|
69
|
+
|
|
70
|
+
const hasRoot = parent && parent.key === ':root'
|
|
71
|
+
if (!ref?.root) {
|
|
72
|
+
ref.root = hasRoot ? element : parentRef?.root
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const createPath = (element, parent, key) => {
|
|
77
|
+
let { __ref: parentRef } = parent
|
|
78
|
+
// set the PATH array
|
|
79
|
+
if (!parentRef) parentRef = parent.ref = {}
|
|
80
|
+
if (!parentRef.path) parentRef.path = []
|
|
81
|
+
return parentRef.path.concat(key)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const addContext = (element, parent, key, options, root) => {
|
|
85
|
+
const forcedOptionsContext =
|
|
86
|
+
options.context && !root.context && !element.context
|
|
87
|
+
if (forcedOptionsContext) root.context = options.context
|
|
88
|
+
|
|
89
|
+
// inherit from parent or root
|
|
90
|
+
return options.context || parent.context || root.context || element.context
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const addCaching = (element, parent, key) => {
|
|
94
|
+
const ref = addRef(element, parent)
|
|
95
|
+
|
|
96
|
+
element.__ref = ref
|
|
97
|
+
|
|
98
|
+
// enable CACHING
|
|
99
|
+
if (!ref.__defineCache) ref.__defineCache = {}
|
|
100
|
+
|
|
101
|
+
// enable EXEC
|
|
102
|
+
if (!ref.__exec) ref.__exec = {}
|
|
103
|
+
if (!ref.__execProps) ref.__execProps = {}
|
|
104
|
+
|
|
105
|
+
// enable CLASS CACHING
|
|
106
|
+
if (!ref.__class) ref.__class = {}
|
|
107
|
+
if (!ref.__classNames) ref.__classNames = {}
|
|
108
|
+
|
|
109
|
+
// enable CLASS CACHING
|
|
110
|
+
if (!ref.__attr) ref.__attr = {}
|
|
111
|
+
|
|
112
|
+
// enable CHANGES storing
|
|
113
|
+
if (!ref.__changes) ref.__changes = []
|
|
114
|
+
|
|
115
|
+
// enable CHANGES storing
|
|
116
|
+
if (!ref.__children) ref.__children = []
|
|
117
|
+
|
|
118
|
+
ref.__extends = createExtends(element, parent, key)
|
|
119
|
+
ref.path = createPath(element, parent, key)
|
|
120
|
+
|
|
121
|
+
return ref
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export const createElement = (passedProps, parentEl, passedKey, opts, root) => {
|
|
125
|
+
const hashed = passedProps?.__hash
|
|
126
|
+
const element = hashed
|
|
127
|
+
? { extends: [passedProps] }
|
|
128
|
+
: createBasedOnType(passedProps, parentEl, passedKey)
|
|
129
|
+
if (!element) return
|
|
130
|
+
|
|
131
|
+
const parent = createParent(element, parentEl, passedKey, opts, root)
|
|
132
|
+
const key = createKey(element, parent, passedKey)
|
|
133
|
+
|
|
134
|
+
addCaching(element, parent, key)
|
|
135
|
+
|
|
136
|
+
const props = createProps(element, parent, key)
|
|
137
|
+
const context = addContext(element, parent, key, opts, root)
|
|
138
|
+
const on = element.on || {}
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
...element,
|
|
142
|
+
key,
|
|
143
|
+
props,
|
|
144
|
+
parent,
|
|
145
|
+
context,
|
|
146
|
+
on
|
|
147
|
+
}
|
|
148
|
+
}
|
package/env.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// @preserve-env
|
|
4
|
+
export const NODE_ENV = process.env.NODE_ENV
|
|
5
|
+
export const ENV = NODE_ENV
|
|
6
|
+
|
|
7
|
+
export const isProduction = (env = NODE_ENV) => env === 'production'
|
|
8
|
+
export const isTest = (env = NODE_ENV) => env === 'testing' || env === 'test'
|
|
9
|
+
export const isTesting = isTest
|
|
10
|
+
export const isStaging = (env = NODE_ENV) => env === 'staging'
|
|
11
|
+
export const isLocal = (env = NODE_ENV) => env === 'local'
|
|
12
|
+
export const isDevelopment = (env = NODE_ENV) =>
|
|
13
|
+
env === 'development' || env === 'dev' || env === 'local'
|
|
14
|
+
export const getNev = (key, env = NODE_ENV) => env[key]
|
|
15
|
+
export const isNotProduction = (env = NODE_ENV) => !isProduction(env)
|
package/events.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { lowercaseFirstLetter } from './string.js'
|
|
4
|
+
import { isFunction } from './types.js'
|
|
5
|
+
|
|
6
|
+
export function addEventFromProps (key, obj) {
|
|
7
|
+
const { props, on } = obj
|
|
8
|
+
const eventName = lowercaseFirstLetter(key.split('on')[1])
|
|
9
|
+
const origEvent = on[eventName]
|
|
10
|
+
const funcFromProps = props[key]
|
|
11
|
+
if (isFunction(origEvent)) {
|
|
12
|
+
on[eventName] = (...args) => {
|
|
13
|
+
const originalEventRetunrs = origEvent(...args)
|
|
14
|
+
if (originalEventRetunrs !== false) {
|
|
15
|
+
if (isFunction(funcFromProps)) return funcFromProps(...args)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
} else on[eventName] = funcFromProps
|
|
19
|
+
}
|