@domql/utils 2.3.125 → 2.3.137
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/dist/cjs/index.js +1 -0
- package/dist/cjs/object.js +38 -18
- package/dist/cjs/string.js +31 -0
- package/index.js +1 -0
- package/object.js +38 -22
- package/package.json +2 -2
- package/string.js +10 -0
package/dist/cjs/index.js
CHANGED
|
@@ -22,3 +22,4 @@ __reExport(utils_exports, require("./function.js"), module.exports);
|
|
|
22
22
|
__reExport(utils_exports, require("./array.js"), module.exports);
|
|
23
23
|
__reExport(utils_exports, require("./node.js"), module.exports);
|
|
24
24
|
__reExport(utils_exports, require("./log.js"), module.exports);
|
|
25
|
+
__reExport(utils_exports, require("./string.js"), module.exports);
|
package/dist/cjs/object.js
CHANGED
|
@@ -35,16 +35,18 @@ __export(object_exports, {
|
|
|
35
35
|
merge: () => merge,
|
|
36
36
|
mergeArrayExclude: () => mergeArrayExclude,
|
|
37
37
|
mergeIfExisted: () => mergeIfExisted,
|
|
38
|
+
objectToString: () => objectToString,
|
|
38
39
|
overwrite: () => overwrite,
|
|
39
40
|
overwriteDeep: () => overwriteDeep,
|
|
40
|
-
overwriteObj: () => overwriteObj,
|
|
41
41
|
overwriteShallow: () => overwriteShallow,
|
|
42
|
-
removeFromObject: () => removeFromObject
|
|
42
|
+
removeFromObject: () => removeFromObject,
|
|
43
|
+
stringToObject: () => stringToObject
|
|
43
44
|
});
|
|
44
45
|
module.exports = __toCommonJS(object_exports);
|
|
45
46
|
var import_globals = require("@domql/globals");
|
|
46
47
|
var import_types = require("./types.js");
|
|
47
48
|
var import_array = require("./array.js");
|
|
49
|
+
var import_string = require("./string.js");
|
|
48
50
|
const exec = (param, element, state, context) => {
|
|
49
51
|
if ((0, import_types.isFunction)(param)) {
|
|
50
52
|
return param(
|
|
@@ -161,6 +163,25 @@ const deepStringify = (obj, stringified = {}) => {
|
|
|
161
163
|
}
|
|
162
164
|
return stringified;
|
|
163
165
|
};
|
|
166
|
+
const objectToString = (obj, indent = 0) => {
|
|
167
|
+
const spaces = " ".repeat(indent);
|
|
168
|
+
let str = "{\n";
|
|
169
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
170
|
+
const keyAllowdChars = (0, import_string.stringIncludesAny)(key, ["-", ":"]);
|
|
171
|
+
const stringedKey = keyAllowdChars ? `'${key}'` : key;
|
|
172
|
+
str += `${spaces} ${stringedKey}: `;
|
|
173
|
+
if (typeof value === "object" && value !== null) {
|
|
174
|
+
str += objectToString(value, indent + 1);
|
|
175
|
+
} else if (typeof value === "string") {
|
|
176
|
+
str += `'${value}'`;
|
|
177
|
+
} else {
|
|
178
|
+
str += value;
|
|
179
|
+
}
|
|
180
|
+
str += ",\n";
|
|
181
|
+
}
|
|
182
|
+
str += `${spaces}}`;
|
|
183
|
+
return str;
|
|
184
|
+
};
|
|
164
185
|
const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
165
186
|
for (const prop in obj) {
|
|
166
187
|
const objProp = obj[prop];
|
|
@@ -231,20 +252,15 @@ const deepDestringify = (obj, stringified = {}) => {
|
|
|
231
252
|
}
|
|
232
253
|
return stringified;
|
|
233
254
|
};
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const elementProp = element[e];
|
|
241
|
-
const paramsProp = params[e];
|
|
242
|
-
if (paramsProp) {
|
|
243
|
-
ref.__cache[e] = changes[e] = elementProp;
|
|
244
|
-
ref[e] = paramsProp;
|
|
245
|
-
}
|
|
255
|
+
const stringToObject = (str) => {
|
|
256
|
+
let obj;
|
|
257
|
+
try {
|
|
258
|
+
obj = import_globals.window.eval("(" + str + ")");
|
|
259
|
+
} catch (e) {
|
|
260
|
+
console.warn(e);
|
|
246
261
|
}
|
|
247
|
-
|
|
262
|
+
if (obj)
|
|
263
|
+
return obj;
|
|
248
264
|
};
|
|
249
265
|
const diffObjects = (original, objToDiff, cache) => {
|
|
250
266
|
for (const e in objToDiff) {
|
|
@@ -287,13 +303,17 @@ const diff = (original, objToDiff, cache = {}) => {
|
|
|
287
303
|
}
|
|
288
304
|
return cache;
|
|
289
305
|
};
|
|
290
|
-
const
|
|
306
|
+
const overwrite = (element, params, excludeFrom = []) => {
|
|
307
|
+
const { ref } = element;
|
|
291
308
|
const changes = {};
|
|
292
309
|
for (const e in params) {
|
|
293
|
-
|
|
310
|
+
if (excludeFrom.includes(e) || e.includes("__"))
|
|
311
|
+
continue;
|
|
312
|
+
const elementProp = element[e];
|
|
294
313
|
const paramsProp = params[e];
|
|
295
314
|
if (paramsProp) {
|
|
296
|
-
|
|
315
|
+
ref.__cache[e] = changes[e] = elementProp;
|
|
316
|
+
ref[e] = paramsProp;
|
|
297
317
|
}
|
|
298
318
|
}
|
|
299
319
|
return changes;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var string_exports = {};
|
|
20
|
+
__export(string_exports, {
|
|
21
|
+
stringIncludesAny: () => stringIncludesAny
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(string_exports);
|
|
24
|
+
const stringIncludesAny = (str, characters) => {
|
|
25
|
+
for (const char of characters) {
|
|
26
|
+
if (str.includes(char)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
package/index.js
CHANGED
package/object.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { window } from '@domql/globals'
|
|
4
4
|
import { isFunction, isObjectLike, isObject, isArray, isString, is } from './types.js'
|
|
5
5
|
import { mergeAndCloneIfArray, mergeArray } from './array.js'
|
|
6
|
+
import { stringIncludesAny } from './string.js'
|
|
6
7
|
|
|
7
8
|
export const exec = (param, element, state, context) => {
|
|
8
9
|
if (isFunction(param)) {
|
|
@@ -135,6 +136,30 @@ export const deepStringify = (obj, stringified = {}) => {
|
|
|
135
136
|
return stringified
|
|
136
137
|
}
|
|
137
138
|
|
|
139
|
+
export const objectToString = (obj, indent = 0) => {
|
|
140
|
+
const spaces = ' '.repeat(indent)
|
|
141
|
+
let str = '{\n'
|
|
142
|
+
|
|
143
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
144
|
+
const keyAllowdChars = stringIncludesAny(key, ['-', ':'])
|
|
145
|
+
const stringedKey = keyAllowdChars ? `'${key}'` : key
|
|
146
|
+
str += `${spaces} ${stringedKey}: `
|
|
147
|
+
|
|
148
|
+
if (typeof value === 'object' && value !== null) {
|
|
149
|
+
str += objectToString(value, indent + 1)
|
|
150
|
+
} else if (typeof value === 'string') {
|
|
151
|
+
str += `'${value}'`
|
|
152
|
+
} else {
|
|
153
|
+
str += value
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
str += ',\n'
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
str += `${spaces}}`
|
|
160
|
+
return str
|
|
161
|
+
}
|
|
162
|
+
|
|
138
163
|
/**
|
|
139
164
|
* Stringify object
|
|
140
165
|
*/
|
|
@@ -205,26 +230,13 @@ export const deepDestringify = (obj, stringified = {}) => {
|
|
|
205
230
|
return stringified
|
|
206
231
|
}
|
|
207
232
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const changes = {}
|
|
214
|
-
|
|
215
|
-
for (const e in params) {
|
|
216
|
-
if (excludeFrom.includes(e) || e.includes('__')) continue
|
|
217
|
-
|
|
218
|
-
const elementProp = element[e]
|
|
219
|
-
const paramsProp = params[e]
|
|
220
|
-
|
|
221
|
-
if (paramsProp) {
|
|
222
|
-
ref.__cache[e] = changes[e] = elementProp
|
|
223
|
-
ref[e] = paramsProp
|
|
224
|
-
}
|
|
225
|
-
}
|
|
233
|
+
export const stringToObject = (str) => {
|
|
234
|
+
let obj
|
|
235
|
+
try {
|
|
236
|
+
obj = window.eval('(' + str + ')') // eslint-disable-line
|
|
237
|
+
} catch (e) { console.warn(e) }
|
|
226
238
|
|
|
227
|
-
return
|
|
239
|
+
if (obj) return obj
|
|
228
240
|
}
|
|
229
241
|
|
|
230
242
|
export const diffObjects = (original, objToDiff, cache) => {
|
|
@@ -276,15 +288,19 @@ export const diff = (original, objToDiff, cache = {}) => {
|
|
|
276
288
|
/**
|
|
277
289
|
* Overwrites object properties with another
|
|
278
290
|
*/
|
|
279
|
-
export const
|
|
291
|
+
export const overwrite = (element, params, excludeFrom = []) => {
|
|
292
|
+
const { ref } = element
|
|
280
293
|
const changes = {}
|
|
281
294
|
|
|
282
295
|
for (const e in params) {
|
|
283
|
-
|
|
296
|
+
if (excludeFrom.includes(e) || e.includes('__')) continue
|
|
297
|
+
|
|
298
|
+
const elementProp = element[e]
|
|
284
299
|
const paramsProp = params[e]
|
|
285
300
|
|
|
286
301
|
if (paramsProp) {
|
|
287
|
-
|
|
302
|
+
ref.__cache[e] = changes[e] = elementProp
|
|
303
|
+
ref[e] = paramsProp
|
|
288
304
|
}
|
|
289
305
|
}
|
|
290
306
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.137",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@domql/key": "latest",
|
|
24
24
|
"@domql/tags": "latest"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "07ca3db13100667ebe3915db37a18b6e694a3ce3",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|