@domql/utils 2.3.5 → 2.3.7
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/array.js +1 -0
- package/function.js +23 -0
- package/index.js +3 -0
- package/object.js +1 -62
- package/package.json +2 -2
- package/types.js +50 -0
package/array.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict'
|
package/function.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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/index.js
CHANGED
package/object.js
CHANGED
|
@@ -1,53 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export const isValidHtmlTag = arg => HTML_TAGS.body.indexOf(arg)
|
|
6
|
-
|
|
7
|
-
export const isObject = arg => {
|
|
8
|
-
if (arg === null) return false
|
|
9
|
-
return (typeof arg === 'object') && (arg.constructor === Object)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const isString = arg => typeof arg === 'string'
|
|
13
|
-
|
|
14
|
-
export const isNumber = arg => typeof arg === 'number'
|
|
15
|
-
|
|
16
|
-
export const isFunction = arg => typeof arg === 'function'
|
|
17
|
-
|
|
18
|
-
export const isArray = arg => Array.isArray(arg)
|
|
19
|
-
|
|
20
|
-
export const isObjectLike = arg => {
|
|
21
|
-
if (arg === null) return false
|
|
22
|
-
// if (isArray(arg)) return false
|
|
23
|
-
return (typeof arg === 'object')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const isNode = obj => {
|
|
27
|
-
return (
|
|
28
|
-
typeof window.Node === 'object'
|
|
29
|
-
? obj instanceof window.Node
|
|
30
|
-
: obj && typeof obj === 'object' && typeof obj.nodeType === 'number' && typeof obj.nodeName === 'string'
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const isHtmlElement = obj => {
|
|
35
|
-
return (
|
|
36
|
-
typeof window.HTMLElement === 'object'
|
|
37
|
-
? obj instanceof window.HTMLElement // DOM2
|
|
38
|
-
: obj && typeof obj === 'object' && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === 'string'
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const isDefined = arg => {
|
|
43
|
-
return isObject(arg) ||
|
|
44
|
-
isObjectLike(arg) ||
|
|
45
|
-
isString(arg) ||
|
|
46
|
-
isNumber(arg) ||
|
|
47
|
-
isFunction(arg) ||
|
|
48
|
-
isArray(arg) ||
|
|
49
|
-
isObjectLike(arg)
|
|
50
|
-
}
|
|
3
|
+
import { isFunction, isObjectLike, isObject, isArray } from './types'
|
|
51
4
|
|
|
52
5
|
export const exec = (param, element, state) => {
|
|
53
6
|
if (isFunction(param)) return param(element, state || element.state)
|
|
@@ -223,17 +176,3 @@ export const flattenRecursive = (param, prop, stack = []) => {
|
|
|
223
176
|
|
|
224
177
|
return stack
|
|
225
178
|
}
|
|
226
|
-
|
|
227
|
-
export const memoize = (fn) => {
|
|
228
|
-
const cache = {}
|
|
229
|
-
return (...args) => {
|
|
230
|
-
const n = args[0]
|
|
231
|
-
if (n in cache) {
|
|
232
|
-
return cache[n]
|
|
233
|
-
} else {
|
|
234
|
-
const result = fn(n)
|
|
235
|
-
cache[n] = result
|
|
236
|
-
return result
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.7",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@domql/tags": "latest"
|
|
8
8
|
},
|
|
9
|
-
"gitHead": "
|
|
9
|
+
"gitHead": "c8dcd776f492f22109580cc44aa5db7e13d43bde",
|
|
10
10
|
"source": "index.js"
|
|
11
11
|
}
|
package/types.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { HTML_TAGS } from '@domql/tags'
|
|
4
|
+
|
|
5
|
+
export const isValidHtmlTag = arg => HTML_TAGS.body.indexOf(arg)
|
|
6
|
+
|
|
7
|
+
export const isObject = arg => {
|
|
8
|
+
if (arg === null) return false
|
|
9
|
+
return (typeof arg === 'object') && (arg.constructor === Object)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const isString = arg => typeof arg === 'string'
|
|
13
|
+
|
|
14
|
+
export const isNumber = arg => typeof arg === 'number'
|
|
15
|
+
|
|
16
|
+
export const isFunction = arg => typeof arg === 'function'
|
|
17
|
+
|
|
18
|
+
export const isArray = arg => Array.isArray(arg)
|
|
19
|
+
|
|
20
|
+
export const isObjectLike = arg => {
|
|
21
|
+
if (arg === null) return false
|
|
22
|
+
// if (isArray(arg)) return false
|
|
23
|
+
return (typeof arg === 'object')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const isNode = obj => {
|
|
27
|
+
return (
|
|
28
|
+
typeof window.Node === 'object'
|
|
29
|
+
? obj instanceof window.Node
|
|
30
|
+
: obj && typeof obj === 'object' && typeof obj.nodeType === 'number' && typeof obj.nodeName === 'string'
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const isHtmlElement = obj => {
|
|
35
|
+
return (
|
|
36
|
+
typeof window.HTMLElement === 'object'
|
|
37
|
+
? obj instanceof window.HTMLElement // DOM2
|
|
38
|
+
: obj && typeof obj === 'object' && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === 'string'
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const isDefined = arg => {
|
|
43
|
+
return isObject(arg) ||
|
|
44
|
+
isObjectLike(arg) ||
|
|
45
|
+
isString(arg) ||
|
|
46
|
+
isNumber(arg) ||
|
|
47
|
+
isFunction(arg) ||
|
|
48
|
+
isArray(arg) ||
|
|
49
|
+
isObjectLike(arg)
|
|
50
|
+
}
|