@domql/utils 2.1.0 → 2.2.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/object.js +39 -7
- package/package.json +3 -3
package/object.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { HTML_TAGS } from '@domql/tags'
|
|
4
4
|
|
|
5
|
-
export const isValidHtmlTag = arg =>
|
|
5
|
+
export const isValidHtmlTag = arg => HTML_TAGS.body.indexOf(arg)
|
|
6
6
|
|
|
7
7
|
export const isObject = arg => {
|
|
8
8
|
if (arg === null) return false
|
|
@@ -119,6 +119,7 @@ export const deepClone = (obj, excluding = ['parent', 'node', '__element', '__ro
|
|
|
119
119
|
* Overwrites object properties with another
|
|
120
120
|
*/
|
|
121
121
|
export const overwrite = (element, params, options) => {
|
|
122
|
+
const { ref } = element
|
|
122
123
|
const changes = {}
|
|
123
124
|
|
|
124
125
|
for (const e in params) {
|
|
@@ -128,11 +129,43 @@ export const overwrite = (element, params, options) => {
|
|
|
128
129
|
const paramsProp = params[e]
|
|
129
130
|
|
|
130
131
|
if (paramsProp) {
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
ref.__cache[e] = changes[e] = elementProp
|
|
133
|
+
ref[e] = paramsProp
|
|
133
134
|
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return changes
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const diff = (obj, original, cache) => {
|
|
141
|
+
const changes = cache || {}
|
|
142
|
+
for (const e in obj) {
|
|
143
|
+
if (e === 'ref') continue
|
|
144
|
+
const originalProp = original[e]
|
|
145
|
+
const objProp = obj[e]
|
|
146
|
+
if (isObjectLike(originalProp) && isObjectLike(objProp)) {
|
|
147
|
+
changes[e] = {}
|
|
148
|
+
diff(originalProp, objProp, changes[e])
|
|
149
|
+
} else if (objProp !== undefined) {
|
|
150
|
+
changes[e] = objProp
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return changes
|
|
154
|
+
}
|
|
134
155
|
|
|
135
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Overwrites object properties with another
|
|
158
|
+
*/
|
|
159
|
+
export const overwriteObj = (params, obj) => {
|
|
160
|
+
const changes = {}
|
|
161
|
+
|
|
162
|
+
for (const e in params) {
|
|
163
|
+
const objProp = obj[e]
|
|
164
|
+
const paramsProp = params[e]
|
|
165
|
+
|
|
166
|
+
if (paramsProp) {
|
|
167
|
+
obj[e] = changes[e] = objProp
|
|
168
|
+
}
|
|
136
169
|
}
|
|
137
170
|
|
|
138
171
|
return changes
|
|
@@ -141,9 +174,8 @@ export const overwrite = (element, params, options) => {
|
|
|
141
174
|
/**
|
|
142
175
|
* Overwrites DEEPly object properties with another
|
|
143
176
|
*/
|
|
144
|
-
export const overwriteDeep = (
|
|
177
|
+
export const overwriteDeep = (params, obj) => {
|
|
145
178
|
for (const e in params) {
|
|
146
|
-
if (excluding.indexOf(e) > -1) continue
|
|
147
179
|
const objProp = obj[e]
|
|
148
180
|
const paramsProp = params[e]
|
|
149
181
|
if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.8",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@domql/
|
|
7
|
+
"@domql/tags": "latest"
|
|
8
8
|
},
|
|
9
|
-
"gitHead": "
|
|
9
|
+
"gitHead": "2870bbc0b27fb7f7e4635b6be6000660880d41cd",
|
|
10
10
|
"source": "index.js"
|
|
11
11
|
}
|