@domql/utils 2.3.29 → 2.3.33

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/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.3.29",
4
- "main": "index.js",
3
+ "version": "2.3.33",
5
4
  "module": "index.js",
5
+ "main": "index.js",
6
+ "browser": "dist/index.cjs.js",
7
+ "files": [
8
+ "dist"
9
+ ],
6
10
  "license": "MIT",
11
+ "scripts": {
12
+ "prepublish": "rm -rf dist && npx esbuild index.js --bundle --target=es2020 --format=cjs --sourcemap=external --outfile=dist/index.cjs.js"
13
+ },
7
14
  "dependencies": {
8
15
  "@domql/globals": "latest",
9
16
  "@domql/tags": "latest"
10
17
  },
11
- "gitHead": "6ed7919e6dc65a6bc48b9711d2dd85afcffe4a17"
18
+ "gitHead": "433b113b5506db37754d113a87aa00475d93d5a1"
12
19
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2016 rackai
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/array.js DELETED
@@ -1 +0,0 @@
1
- 'use strict'
package/function.js DELETED
@@ -1,23 +0,0 @@
1
- 'use strict'
2
-
3
- export const debounce = (element, func, timeout = 300) => {
4
- let timer
5
- return (...args) => {
6
- clearTimeout(timer)
7
- timer = setTimeout(() => { func.apply(element, args) }, timeout)
8
- }
9
- }
10
-
11
- export const memoize = (fn) => {
12
- const cache = {}
13
- return (...args) => {
14
- const n = args[0]
15
- if (n in cache) {
16
- return cache[n]
17
- } else {
18
- const result = fn(n)
19
- cache[n] = result
20
- return result
21
- }
22
- }
23
- }
package/log.js DELETED
@@ -1,10 +0,0 @@
1
- 'use strict'
2
-
3
- export const logIf = (bool, ...arg) => { if (bool) arg.map(v => console.log(v)) }
4
- export const logGroupIf = (bool, key, ...arg) => {
5
- if (bool) {
6
- console.group(key)
7
- arg.map(v => console.log(v))
8
- console.groupEnd(key)
9
- }
10
- }
package/node.js DELETED
@@ -1,16 +0,0 @@
1
- 'use strict'
2
-
3
- export const cleanWithNode = extend => delete extend.node && extend
4
-
5
- export const createID = (function () {
6
- let index = 0
7
-
8
- function newId () {
9
- index++
10
- return index
11
- }
12
-
13
- return newId
14
- })()
15
-
16
- export const createSnapshotId = createID
package/object.js DELETED
@@ -1,266 +0,0 @@
1
- 'use strict'
2
-
3
- import { isFunction, isObjectLike, isObject, isArray, isString } from './types'
4
-
5
- export const exec = (param, element, state) => {
6
- if (isFunction(param)) return param(element, state || element.state)
7
- return param
8
- }
9
-
10
- export const map = (obj, extention, element) => {
11
- for (const e in extention) {
12
- obj[e] = exec(extention[e], element)
13
- }
14
- }
15
-
16
- export const merge = (element, obj) => {
17
- for (const e in obj) {
18
- const elementProp = element[e]
19
- const objProp = obj[e]
20
- if (elementProp === undefined) {
21
- element[e] = objProp
22
- }
23
- }
24
- return element
25
- }
26
-
27
- export const deepMerge = (element, extend) => {
28
- for (const e in extend) {
29
- const elementProp = element[e]
30
- const extendProp = extend[e]
31
- // const cachedProps = cache.props
32
- if (e === 'parent' || e === 'props') continue
33
- if (elementProp === undefined) {
34
- element[e] = extendProp
35
- } else if (isObjectLike(elementProp) && isObject(extendProp)) {
36
- deepMerge(elementProp, extendProp)
37
- }
38
- }
39
- return element
40
- }
41
-
42
- export const clone = obj => {
43
- const o = {}
44
- for (const prop in obj) {
45
- if (prop === 'node') continue
46
- o[prop] = obj[prop]
47
- }
48
- return o
49
- }
50
-
51
- // Clone anything deeply but exclude keys given in 'exclude'
52
- export const deepCloneExclude = (obj, exclude = []) => {
53
- if (isArray(obj)) {
54
- return obj.map(x => deepCloneExclude(x, exclude))
55
- }
56
-
57
- const o = {}
58
- for (const k in obj) {
59
- if (exclude.indexOf(k) > -1) continue
60
-
61
- let v = obj[k]
62
-
63
- if (k === 'extend' && isArray(v)) {
64
- v = mergeArrayExclude(v, exclude)
65
- }
66
-
67
- if (isArray(v)) {
68
- o[k] = v.map(x => deepCloneExclude(x, exclude))
69
- } else if (isObject(v)) {
70
- o[k] = deepCloneExclude(v, exclude)
71
- } else o[k] = v
72
- }
73
-
74
- return o
75
- }
76
-
77
- // Merge array, but exclude keys listed in 'excl'
78
- export const mergeArrayExclude = (arr, excl = []) => {
79
- return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {})
80
- }
81
-
82
- /**
83
- * Deep cloning of object
84
- */
85
- export const deepClone = (obj) => {
86
- if (isArray(obj)) {
87
- return obj.map(deepClone)
88
- }
89
- const o = {}
90
- for (const prop in obj) {
91
- let objProp = obj[prop]
92
- if (prop === 'extend' && isArray(objProp)) {
93
- objProp = mergeArray(objProp)
94
- }
95
- if (isArray(objProp)) {
96
- o[prop] = objProp.map(v => isObject(v) ? deepClone(v) : v)
97
- } else if (isObject(objProp)) {
98
- o[prop] = deepClone(objProp)
99
- } else o[prop] = objProp
100
- }
101
- return o
102
- }
103
-
104
- /**
105
- * Stringify object
106
- */
107
- export const deepStringify = (obj, stringified = {}) => {
108
- for (const prop in obj) {
109
- const objProp = obj[prop]
110
- if (isFunction(objProp)) {
111
- stringified[prop] = objProp.toString()
112
- } else if (isObject(objProp)) {
113
- stringified[prop] = {}
114
- deepStringify(objProp[prop], stringified[prop])
115
- } else if (isArray(objProp)) {
116
- stringified[prop] = []
117
- objProp.map((v, i) => deepStringify(v, stringified[prop][i]))
118
- } else stringified[prop] = objProp
119
- }
120
- return stringified
121
- }
122
-
123
- /**
124
- * Detringify object
125
- */
126
- export const deepDestringify = (obj, stringified = {}) => {
127
- for (const prop in obj) {
128
- const objProp = obj[prop]
129
- if (isString(objProp)) {
130
- if (objProp.includes('=>') || objProp.includes('function') || objProp[0] === '(') {
131
- try {
132
- const evalProp = eval(objProp) // eslint-disable-line
133
- stringified[prop] = evalProp
134
- } catch (e) { if (e) stringified[prop] = objProp }
135
- }
136
- } else stringified[prop] = objProp
137
- if (isObject(objProp)) deepDestringify(stringified[prop], stringified[prop])
138
- }
139
- return stringified
140
- }
141
-
142
- /**
143
- * Overwrites object properties with another
144
- */
145
- export const overwrite = (element, params, options) => {
146
- const { ref } = element
147
- const changes = {}
148
-
149
- for (const e in params) {
150
- if (e === 'props') continue
151
-
152
- const elementProp = element[e]
153
- const paramsProp = params[e]
154
-
155
- if (paramsProp) {
156
- ref.__cache[e] = changes[e] = elementProp
157
- ref[e] = paramsProp
158
- }
159
- }
160
-
161
- return changes
162
- }
163
-
164
- export const diff = (obj, original, cache) => {
165
- const changes = cache || {}
166
- for (const e in obj) {
167
- if (e === 'ref') continue
168
- const originalProp = original[e]
169
- const objProp = obj[e]
170
- if (isObjectLike(originalProp) && isObjectLike(objProp)) {
171
- changes[e] = {}
172
- diff(originalProp, objProp, changes[e])
173
- } else if (objProp !== undefined) {
174
- changes[e] = objProp
175
- }
176
- }
177
- return changes
178
- }
179
-
180
- /**
181
- * Overwrites object properties with another
182
- */
183
- export const overwriteObj = (params, obj) => {
184
- const changes = {}
185
-
186
- for (const e in params) {
187
- const objProp = obj[e]
188
- const paramsProp = params[e]
189
-
190
- if (paramsProp) {
191
- obj[e] = changes[e] = objProp
192
- }
193
- }
194
-
195
- return changes
196
- }
197
-
198
- /**
199
- * Overwrites DEEPly object properties with another
200
- */
201
- export const overwriteDeep = (params, obj) => {
202
- for (const e in params) {
203
- const objProp = obj[e]
204
- const paramsProp = params[e]
205
- if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
206
- overwriteDeep(objProp, paramsProp)
207
- } else if (paramsProp !== undefined) {
208
- obj[e] = paramsProp
209
- }
210
- }
211
- return obj
212
- }
213
-
214
- /**
215
- * Overwrites object properties with another
216
- */
217
- export const mergeIfExisted = (a, b) => {
218
- if (isObjectLike(a) && isObjectLike(b)) return deepMerge(a, b)
219
- return a || b
220
- }
221
-
222
- /**
223
- * Merges array extendtypes
224
- */
225
- export const mergeArray = (arr) => {
226
- return arr.reduce((a, c) => deepMerge(a, deepClone(c)), {})
227
- }
228
-
229
- /**
230
- * Merges array extendtypes
231
- */
232
- export const mergeAndCloneIfArray = obj => {
233
- return isArray(obj) ? mergeArray(obj) : deepClone(obj)
234
- }
235
-
236
- /**
237
- * Overwrites object properties with another
238
- */
239
- export const flattenRecursive = (param, prop, stack = []) => {
240
- const objectized = mergeAndCloneIfArray(param)
241
- stack.push(objectized)
242
-
243
- const extendOfExtend = objectized[prop]
244
- if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack)
245
-
246
- delete objectized[prop]
247
-
248
- return stack
249
- }
250
-
251
- export const isEqualDeep = (param, element) => {
252
- if (param === element) return true
253
- if (!param || !element) return false
254
- for (const prop in param) {
255
- const paramProp = param[prop]
256
- const elementProp = element[prop]
257
- if (isObjectLike(paramProp)) {
258
- const isEqual = isEqualDeep(paramProp, elementProp)
259
- if (!isEqual) return false
260
- } else {
261
- const isEqual = paramProp === elementProp
262
- if (!isEqual) return false
263
- }
264
- }
265
- return true
266
- }
package/types.js DELETED
@@ -1,87 +0,0 @@
1
- 'use strict'
2
-
3
- import { window } from '@domql/globals'
4
- import { HTML_TAGS } from '@domql/tags'
5
-
6
- export const isValidHtmlTag = arg => HTML_TAGS.body.indexOf(arg)
7
-
8
- export const isObject = arg => {
9
- if (arg === null) return false
10
- return (typeof arg === 'object') && (arg.constructor === Object)
11
- }
12
-
13
- export const isString = arg => typeof arg === 'string'
14
-
15
- export const isNumber = arg => typeof arg === 'number'
16
-
17
- export const isFunction = arg => typeof arg === 'function'
18
-
19
- export const isBoolean = arg => arg === true || arg === false
20
-
21
- export const isNull = arg => arg === null
22
-
23
- export const isArray = arg => Array.isArray(arg)
24
-
25
- export const isObjectLike = arg => {
26
- if (arg === null) return false
27
- // if (isArray(arg)) return false
28
- return (typeof arg === 'object')
29
- }
30
-
31
- export const isNode = obj => {
32
- return (
33
- typeof window.Node === 'object'
34
- ? obj instanceof window.Node
35
- : obj && typeof obj === 'object' && typeof obj.nodeType === 'number' && typeof obj.nodeName === 'string'
36
- )
37
- }
38
-
39
- export const isHtmlElement = obj => {
40
- return (
41
- typeof window.HTMLElement === 'object'
42
- ? obj instanceof window.HTMLElement // DOM2
43
- : obj && typeof obj === 'object' && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === 'string'
44
- )
45
- }
46
-
47
- export const isDefined = arg => {
48
- return isObject(arg) ||
49
- isObjectLike(arg) ||
50
- isString(arg) ||
51
- isNumber(arg) ||
52
- isFunction(arg) ||
53
- isArray(arg) ||
54
- isObjectLike(arg) ||
55
- isBoolean(arg) ||
56
- isNull(arg)
57
- }
58
-
59
- export const isUndefined = arg => {
60
- return arg === undefined
61
- }
62
-
63
- export const TYPES = {
64
- boolean: isBoolean,
65
- array: isArray,
66
- object: isObject,
67
- string: isString,
68
- number: isNumber,
69
- null: isNull,
70
- function: isFunction,
71
- objectLike: isObjectLike,
72
- node: isNode,
73
- htmlElement: isHtmlElement,
74
- defined: isDefined
75
- }
76
-
77
- export const is = (arg) => {
78
- return (...args) => {
79
- return args.map(val => TYPES[val](arg)).filter(v => v).length > 0
80
- }
81
- }
82
-
83
- export const isNot = (arg) => {
84
- return (...args) => {
85
- return args.map(val => TYPES[val](arg)).filter(v => v).length === 0
86
- }
87
- }