@domql/utils 2.3.126 → 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 +33 -1
- package/dist/cjs/string.js +31 -0
- package/index.js +1 -0
- package/object.js +34 -0
- 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,15 +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
41
|
overwriteShallow: () => overwriteShallow,
|
|
41
|
-
removeFromObject: () => removeFromObject
|
|
42
|
+
removeFromObject: () => removeFromObject,
|
|
43
|
+
stringToObject: () => stringToObject
|
|
42
44
|
});
|
|
43
45
|
module.exports = __toCommonJS(object_exports);
|
|
44
46
|
var import_globals = require("@domql/globals");
|
|
45
47
|
var import_types = require("./types.js");
|
|
46
48
|
var import_array = require("./array.js");
|
|
49
|
+
var import_string = require("./string.js");
|
|
47
50
|
const exec = (param, element, state, context) => {
|
|
48
51
|
if ((0, import_types.isFunction)(param)) {
|
|
49
52
|
return param(
|
|
@@ -160,6 +163,25 @@ const deepStringify = (obj, stringified = {}) => {
|
|
|
160
163
|
}
|
|
161
164
|
return stringified;
|
|
162
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
|
+
};
|
|
163
185
|
const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
164
186
|
for (const prop in obj) {
|
|
165
187
|
const objProp = obj[prop];
|
|
@@ -230,6 +252,16 @@ const deepDestringify = (obj, stringified = {}) => {
|
|
|
230
252
|
}
|
|
231
253
|
return stringified;
|
|
232
254
|
};
|
|
255
|
+
const stringToObject = (str) => {
|
|
256
|
+
let obj;
|
|
257
|
+
try {
|
|
258
|
+
obj = import_globals.window.eval("(" + str + ")");
|
|
259
|
+
} catch (e) {
|
|
260
|
+
console.warn(e);
|
|
261
|
+
}
|
|
262
|
+
if (obj)
|
|
263
|
+
return obj;
|
|
264
|
+
};
|
|
233
265
|
const diffObjects = (original, objToDiff, cache) => {
|
|
234
266
|
for (const e in objToDiff) {
|
|
235
267
|
if (e === "ref")
|
|
@@ -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,6 +230,15 @@ export const deepDestringify = (obj, stringified = {}) => {
|
|
|
205
230
|
return stringified
|
|
206
231
|
}
|
|
207
232
|
|
|
233
|
+
export const stringToObject = (str) => {
|
|
234
|
+
let obj
|
|
235
|
+
try {
|
|
236
|
+
obj = window.eval('(' + str + ')') // eslint-disable-line
|
|
237
|
+
} catch (e) { console.warn(e) }
|
|
238
|
+
|
|
239
|
+
if (obj) return obj
|
|
240
|
+
}
|
|
241
|
+
|
|
208
242
|
export const diffObjects = (original, objToDiff, cache) => {
|
|
209
243
|
for (const e in objToDiff) {
|
|
210
244
|
if (e === 'ref') continue
|
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
|
}
|