@symbo.ls/utils 3.14.2 → 3.14.3
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 +7 -0
- package/dist/cjs/array.cjs +1 -0
- package/dist/cjs/assets.cjs +1 -0
- package/dist/cjs/browser.cjs +1 -0
- package/dist/cjs/cache.cjs +1 -0
- package/dist/cjs/cdn.cjs +3 -0
- package/dist/cjs/component.cjs +1 -0
- package/dist/cjs/cookie.cjs +1 -0
- package/dist/cjs/date.cjs +1 -0
- package/dist/cjs/detectHeight.cjs +1 -0
- package/dist/cjs/element.cjs +1 -0
- package/dist/cjs/env.cjs +2 -0
- package/dist/cjs/events.cjs +1 -0
- package/dist/cjs/extends.cjs +1 -0
- package/dist/cjs/fibonacci.cjs +1 -0
- package/dist/cjs/files.cjs +1 -0
- package/dist/cjs/function.cjs +1 -0
- package/dist/cjs/globals.cjs +1 -0
- package/dist/cjs/if.cjs +1 -0
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/key.cjs +1 -0
- package/dist/cjs/keys.cjs +1 -0
- package/dist/cjs/load.cjs +1 -0
- package/dist/cjs/log.cjs +1 -0
- package/dist/cjs/metadata.cjs +2 -0
- package/dist/cjs/methods.cjs +10 -0
- package/dist/cjs/node.cjs +1 -0
- package/dist/cjs/object.cjs +12 -0
- package/dist/cjs/projectKeys.cjs +1 -0
- package/dist/cjs/props.cjs +1 -0
- package/dist/cjs/scaling.cjs +1 -0
- package/dist/cjs/scope.cjs +1 -0
- package/dist/cjs/sharedLibraries.cjs +1 -0
- package/dist/cjs/state.cjs +1 -0
- package/dist/cjs/string-extra.cjs +1 -0
- package/dist/cjs/string.cjs +3 -0
- package/dist/cjs/style.cjs +1 -0
- package/dist/cjs/tags.cjs +1 -0
- package/dist/cjs/triggerEvent.cjs +1 -0
- package/dist/cjs/types.cjs +1 -0
- package/dist/cjs/update.cjs +1 -0
- package/dist/esm/array.js +1 -0
- package/dist/esm/assets.js +1 -0
- package/dist/esm/browser.js +1 -0
- package/dist/esm/cache.js +1 -0
- package/dist/esm/cdn.js +3 -0
- package/dist/esm/component.js +1 -0
- package/dist/esm/cookie.js +1 -0
- package/dist/esm/date.js +1 -0
- package/dist/esm/detectHeight.js +1 -0
- package/dist/esm/element.js +1 -0
- package/dist/esm/env.js +2 -0
- package/dist/esm/events.js +1 -0
- package/dist/esm/extends.js +1 -0
- package/dist/esm/fibonacci.js +1 -0
- package/dist/esm/files.js +1 -0
- package/dist/esm/function.js +1 -0
- package/dist/esm/globals.js +1 -0
- package/dist/esm/if.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/key.js +1 -0
- package/dist/esm/keys.js +1 -0
- package/dist/esm/load.js +1 -0
- package/dist/esm/log.js +1 -0
- package/dist/esm/metadata.js +2 -0
- package/dist/esm/methods.js +10 -0
- package/dist/esm/node.js +1 -0
- package/dist/esm/object.js +12 -0
- package/dist/esm/projectKeys.js +1 -0
- package/dist/esm/props.js +1 -0
- package/dist/esm/scaling.js +1 -0
- package/dist/esm/scope.js +1 -0
- package/dist/esm/sharedLibraries.js +1 -0
- package/dist/esm/state.js +1 -0
- package/dist/esm/string-extra.js +1 -0
- package/dist/esm/string.js +3 -0
- package/dist/esm/style.js +1 -0
- package/dist/esm/tags.js +1 -0
- package/dist/esm/triggerEvent.js +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/update.js +1 -0
- package/package.json +35 -18
- package/array.js +0 -162
- package/assets.js +0 -117
- package/browser.js +0 -13
- package/cache.js +0 -7
- package/cdn.js +0 -83
- package/component.js +0 -25
- package/cookie.js +0 -78
- package/date.js +0 -10
- package/detectHeight.js +0 -42
- package/element.js +0 -148
- package/env.js +0 -15
- package/events.js +0 -19
- package/extends.js +0 -519
- package/fibonacci.js +0 -9
- package/files.js +0 -3
- package/function.js +0 -145
- package/globals.js +0 -8
- package/if.js +0 -30
- package/index.js +0 -42
- package/key.js +0 -20
- package/keys.js +0 -176
- package/load.js +0 -236
- package/log.js +0 -12
- package/metadata.js +0 -392
- package/methods.js +0 -684
- package/node.js +0 -37
- package/object.js +0 -837
- package/projectKeys.js +0 -30
- package/props.js +0 -327
- package/scaling.js +0 -15
- package/scope.js +0 -32
- package/sharedLibraries.js +0 -184
- package/state.js +0 -203
- package/string-extra.js +0 -69
- package/string.js +0 -206
- package/style.js +0 -23
- package/tags.js +0 -176
- package/triggerEvent.js +0 -102
- package/types.js +0 -55
- package/update.js +0 -27
package/cookie.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { isUndefined } from './types.js'
|
|
4
|
-
import { document } from './globals.js'
|
|
5
|
-
|
|
6
|
-
export const isMobile = (() =>
|
|
7
|
-
typeof navigator === 'undefined' ? false : /Mobi/.test(navigator.userAgent))()
|
|
8
|
-
|
|
9
|
-
export const setCookie = (cname, cvalue, exdays = 365) => {
|
|
10
|
-
if (isUndefined(document) || isUndefined(document.cookie)) return
|
|
11
|
-
const d = new Date()
|
|
12
|
-
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000)
|
|
13
|
-
const expires = `expires=${d.toUTCString()}`
|
|
14
|
-
document.cookie = `${cname}=${cvalue};${expires};path=/`
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const getCookie = cname => {
|
|
18
|
-
if (isUndefined(document) || isUndefined(document.cookie)) return
|
|
19
|
-
const name = `${cname}=`
|
|
20
|
-
const decodedCookie = decodeURIComponent(document.cookie)
|
|
21
|
-
const ca = decodedCookie.split(';')
|
|
22
|
-
for (let i = 0; i < ca.length; i++) {
|
|
23
|
-
let c = ca[i]
|
|
24
|
-
while (c.charAt(0) === ' ') c = c.substring(1)
|
|
25
|
-
if (c.indexOf(name) === 0) return c.substring(name.length, c.length)
|
|
26
|
-
}
|
|
27
|
-
return ''
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const removeCookie = cname => {
|
|
31
|
-
if (isUndefined(document) || isUndefined(document.cookie)) return
|
|
32
|
-
document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Load item from the localStorage
|
|
36
|
-
*
|
|
37
|
-
* @param key -- string to identify the storage item
|
|
38
|
-
* @returns {*} -- parsed data or undefined
|
|
39
|
-
*/
|
|
40
|
-
export function getLocalStorage (key) {
|
|
41
|
-
// localStorage access throws in: Safari private mode (quota), sandboxed
|
|
42
|
-
// iframes without `allow-storage-access-by-user-activation`, Firefox with
|
|
43
|
-
// `dom.storage.enabled=false`. Wrap the access itself, not just the
|
|
44
|
-
// JSON.parse — the existing try only covered parse and let the read
|
|
45
|
-
// crash the host.
|
|
46
|
-
let item
|
|
47
|
-
try {
|
|
48
|
-
if (!window.localStorage) return undefined
|
|
49
|
-
item = window.localStorage.getItem(key)
|
|
50
|
-
} catch (e) {
|
|
51
|
-
return undefined
|
|
52
|
-
}
|
|
53
|
-
if (item === null) return undefined
|
|
54
|
-
try {
|
|
55
|
-
return JSON.parse(item)
|
|
56
|
-
} catch (e) {
|
|
57
|
-
return undefined
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Save the data to window.localStorage
|
|
63
|
-
*
|
|
64
|
-
* @param key - local storage key to save the data under
|
|
65
|
-
* @param data - the data to save
|
|
66
|
-
*/
|
|
67
|
-
export function setLocalStorage (key, data) {
|
|
68
|
-
if (data === undefined || data === null) return
|
|
69
|
-
try {
|
|
70
|
-
if (!window.localStorage) return
|
|
71
|
-
const value = typeof data === 'object' ? JSON.stringify(data) : data
|
|
72
|
-
window.localStorage.setItem(key, value)
|
|
73
|
-
} catch (e) {
|
|
74
|
-
// QuotaExceededError (Safari private + over quota), SecurityError
|
|
75
|
-
// (sandboxed iframe / disabled storage). Silent fail — caller doesn't
|
|
76
|
-
// expect an exception out of a "save best-effort" helper.
|
|
77
|
-
}
|
|
78
|
-
}
|
package/date.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
export const formatDate = (timestamp) => {
|
|
4
|
-
if (!timestamp) return ''
|
|
5
|
-
const d = new Date(timestamp)
|
|
6
|
-
const ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d)
|
|
7
|
-
const mo = new Intl.DateTimeFormat('en', { month: 'short' }).format(d)
|
|
8
|
-
const da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d)
|
|
9
|
-
return `${da} ${mo}, ${ye}`
|
|
10
|
-
}
|
package/detectHeight.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
export const detectHeightOnInit = (element, state) => {
|
|
4
|
-
const heightTimeout = setTimeout(() => {
|
|
5
|
-
const { props } = element
|
|
6
|
-
if (!state.clientHeight) {
|
|
7
|
-
const {
|
|
8
|
-
node: { clientHeight }
|
|
9
|
-
} = element
|
|
10
|
-
if (clientHeight) {
|
|
11
|
-
state.clientHeight = clientHeight
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (state.active) {
|
|
16
|
-
if (props.height === 'auto') return
|
|
17
|
-
element.update(
|
|
18
|
-
{
|
|
19
|
-
height: state.clientHeight
|
|
20
|
-
},
|
|
21
|
-
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
22
|
-
)
|
|
23
|
-
const setAutoTimeout = setTimeout(() => {
|
|
24
|
-
element.update(
|
|
25
|
-
{
|
|
26
|
-
height: 'auto'
|
|
27
|
-
},
|
|
28
|
-
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
29
|
-
)
|
|
30
|
-
clearTimeout(setAutoTimeout)
|
|
31
|
-
}, 450)
|
|
32
|
-
} else {
|
|
33
|
-
element.update(
|
|
34
|
-
{
|
|
35
|
-
height: '0'
|
|
36
|
-
},
|
|
37
|
-
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
clearTimeout(heightTimeout)
|
|
41
|
-
})
|
|
42
|
-
}
|
package/element.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|