@domql/utils 2.3.0 → 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 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
@@ -1,4 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ export * from './types'
3
4
  export * from './object'
5
+ export * from './function'
6
+ export * from './array'
4
7
  export * from './node'
package/object.js CHANGED
@@ -1,53 +1,6 @@
1
1
  'use strict'
2
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
- }
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)
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.3.0",
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": "02944ad228d2cf5f5727b08e9378d221b2f7205b",
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
+ }