@domql/utils 2.3.5 → 2.3.8

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)
@@ -224,16 +177,19 @@ export const flattenRecursive = (param, prop, stack = []) => {
224
177
  return stack
225
178
  }
226
179
 
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]
180
+ export const isEqualDeep = (param, element) => {
181
+ if (param === element) return true
182
+ if (!param || !element) return false
183
+ for (const prop in param) {
184
+ const paramProp = param[prop]
185
+ const elementProp = element[prop]
186
+ if (isObjectLike(paramProp)) {
187
+ const isEqual = isEqualDeep(paramProp, elementProp)
188
+ if (!isEqual) return false
233
189
  } else {
234
- const result = fn(n)
235
- cache[n] = result
236
- return result
190
+ const isEqual = paramProp === elementProp
191
+ if (!isEqual) return false
237
192
  }
238
193
  }
194
+ return true
239
195
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.3.5",
3
+ "version": "2.3.8",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
7
  "@domql/tags": "latest"
8
8
  },
9
- "gitHead": "9f1a47a59fa1512a593714401583b8286e6f2bff",
9
+ "gitHead": "0806fd53e029721c87db84d21a3e46a8a23cef24",
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
+ }