@domql/utils 2.0.2 → 2.0.6

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.
@@ -2,4 +2,3 @@
2
2
 
3
3
  export * from './object'
4
4
  export * from './node'
5
- export * from './protoUtils'
File without changes
@@ -1,8 +1,8 @@
1
1
  'use strict'
2
2
 
3
- import { NODE_REGISTRY } from '@domql/node'
3
+ import { TAGS } from '@domql/registry'
4
4
 
5
- export const isValidHtmlTag = arg => NODE_REGISTRY.body.indexOf(arg)
5
+ export const isValidHtmlTag = arg => TAGS.body.indexOf(arg)
6
6
 
7
7
  export const isObject = arg => {
8
8
  if (arg === null) return false
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.0.2",
4
- "main": "src/index.js",
3
+ "version": "2.0.6",
4
+ "main": "index.js",
5
5
  "license": "MIT",
6
- "scripts": {
7
- "vpatch": "npm version patch && npm publish --access public"
8
- },
9
6
  "dependencies": {
10
- "@domql/node": "^2.0.2"
7
+ "@domql/registry": "^2.0.6"
11
8
  },
12
- "gitHead": "0aa5932cb9ae5f1bb55bfaf792a4d009233385f6",
13
- "source": "src/index.js"
9
+ "gitHead": "88144a3105a3a0abd5f54f31659a37e494418dcb",
10
+ "source": "index.js"
14
11
  }
package/src/protoUtils.js DELETED
@@ -1,119 +0,0 @@
1
- 'use strict'
2
-
3
- import { isArray, isFunction, isObject } from './object'
4
-
5
- export const generateHash = () => Math.random().toString(36).substring(2)
6
-
7
- // hashing
8
- export const protoStackRegistry = {}
9
- export const protoCachedRegistry = {}
10
-
11
- window.protoStackRegistry = protoStackRegistry
12
- window.protoCachedRegistry = protoCachedRegistry
13
-
14
- export const getHashedProto = proto => {
15
- return protoStackRegistry[proto.__hash]
16
- }
17
-
18
- export const setHashedProto = (proto, stack) => {
19
- const hash = generateHash()
20
- proto.__hash = hash
21
- protoStackRegistry[hash] = stack
22
- return protoStackRegistry[hash]
23
- }
24
-
25
- export const getProtoStackRegistry = (proto, stack) => {
26
- if (proto.__hash) {
27
- return stack.concat(getHashedProto(proto))
28
- } else {
29
- setHashedProto(proto, stack)
30
- }
31
- return stack // .concat(hashedProto)
32
- }
33
-
34
- // stacking
35
- export const extractArrayProto = (proto, stack) => {
36
- proto.forEach(each => flattenProto(each, stack))
37
- return stack
38
- }
39
-
40
- export const deepProto = (proto, stack) => {
41
- const protoOflattenProto = proto.proto
42
- if (protoOflattenProto) {
43
- flattenProto(protoOflattenProto, stack)
44
- }
45
- return stack
46
- }
47
-
48
- export const flattenProto = (proto, stack) => {
49
- if (!proto) return stack
50
- if (isArray(proto)) return extractArrayProto(proto, stack)
51
- stack.push(proto)
52
- if (proto.proto) deepProto(proto, stack)
53
- return stack
54
- }
55
-
56
- // merging
57
- export const deepCloneProto = obj => {
58
- const o = {}
59
- for (const prop in obj) {
60
- if (['parent', 'node', '__element', '__root', '__key'].indexOf(prop) > -1) continue
61
- const objProp = obj[prop]
62
- if (isObject(objProp)) {
63
- o[prop] = deepCloneProto(objProp)
64
- } else if (isArray(objProp)) {
65
- o[prop] = objProp.map(x => x)
66
- } else o[prop] = objProp
67
- }
68
- return o
69
- }
70
-
71
- export const deepMergeProto = (element, proto) => {
72
- for (const e in proto) {
73
- if (['parent', 'node', '__element', '__root'].indexOf(e) > -1) continue
74
- const elementProp = element[e]
75
- const protoProp = proto[e]
76
- if (elementProp === undefined) {
77
- element[e] = protoProp
78
- } else if (isObject(elementProp) && isObject(protoProp)) {
79
- deepMergeProto(elementProp, protoProp)
80
- } else if (isArray(elementProp) && isArray(protoProp)) {
81
- element[e] = elementProp.concat(protoProp)
82
- } else if (isArray(elementProp) && isObject(protoProp)) {
83
- const obj = deepMergeProto({}, elementProp)
84
- element[e] = deepMergeProto(obj, protoProp)
85
- } else if (elementProp === undefined && isFunction(protoProp)) {
86
- element[e] = protoProp
87
- }
88
- }
89
- return element
90
- }
91
-
92
- export const cloneAndMergeArrayProto = stack => {
93
- return stack.reduce((a, c) => {
94
- return deepMergeProto(a, deepCloneProto(c))
95
- }, {})
96
- }
97
-
98
- // joint stacks
99
- export const jointStacks = (protoStack, childProtoStack) => {
100
- return []
101
- .concat(protoStack.slice(0, 1))
102
- .concat(childProtoStack.slice(0, 1))
103
- .concat(protoStack.slice(1))
104
- .concat(childProtoStack.slice(1))
105
- }
106
-
107
- // init
108
- export const getProtoStack = proto => {
109
- if (!proto) return []
110
- if (proto.__hash) return getHashedProto(proto)
111
- const stack = flattenProto(proto, [])
112
- // console.log(stack)
113
- return getProtoStackRegistry(proto, stack)
114
- }
115
-
116
- export const getProtoMerged = proto => {
117
- const stack = getProtoStack(proto)
118
- return cloneAndMergeArrayProto(stack)
119
- }