@domql/utils 2.5.35 → 2.5.38
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/object.js +19 -1
- package/dist/cjs/string.js +6 -1
- package/object.js +17 -1
- package/package.json +2 -2
- package/string.js +9 -0
package/dist/cjs/object.js
CHANGED
|
@@ -21,6 +21,7 @@ __export(object_exports, {
|
|
|
21
21
|
clone: () => clone,
|
|
22
22
|
deepClone: () => deepClone,
|
|
23
23
|
deepCloneExclude: () => deepCloneExclude,
|
|
24
|
+
deepCloneWithExtnd: () => deepCloneWithExtnd,
|
|
24
25
|
deepContains: () => deepContains,
|
|
25
26
|
deepDestringify: () => deepDestringify,
|
|
26
27
|
deepDiff: () => deepDiff,
|
|
@@ -151,6 +152,23 @@ const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
|
|
|
151
152
|
}
|
|
152
153
|
return o;
|
|
153
154
|
};
|
|
155
|
+
const deepCloneWithExtnd = (obj, excludeFrom = [], cleanUndefined = false) => {
|
|
156
|
+
const o = (0, import_types.isArray)(obj) ? [] : {};
|
|
157
|
+
for (const prop in obj) {
|
|
158
|
+
if (prop === "__proto__")
|
|
159
|
+
continue;
|
|
160
|
+
if (excludeFrom.includes(prop) || prop.startsWith("__"))
|
|
161
|
+
continue;
|
|
162
|
+
const objProp = obj[prop];
|
|
163
|
+
if (cleanUndefined && (0, import_types.isUndefined)(objProp))
|
|
164
|
+
continue;
|
|
165
|
+
if ((0, import_types.isObjectLike)(objProp)) {
|
|
166
|
+
o[prop] = deepClone(objProp, excludeFrom, cleanUndefined);
|
|
167
|
+
} else
|
|
168
|
+
o[prop] = objProp;
|
|
169
|
+
}
|
|
170
|
+
return o;
|
|
171
|
+
};
|
|
154
172
|
const deepStringify = (obj, stringified = {}) => {
|
|
155
173
|
for (const prop in obj) {
|
|
156
174
|
const objProp = obj[prop];
|
|
@@ -181,7 +199,7 @@ const objectToString = (obj, indent = 0) => {
|
|
|
181
199
|
const spaces = " ".repeat(indent);
|
|
182
200
|
let str = "{\n";
|
|
183
201
|
for (const [key, value] of Object.entries(obj)) {
|
|
184
|
-
const keyNotAllowdChars = (0, import_string.stringIncludesAny)(key, ["-", ":", "@", ".", "/", "!"]);
|
|
202
|
+
const keyNotAllowdChars = (0, import_string.stringIncludesAny)(key, ["&", "*", "-", ":", "@", ".", "/", "!", " "]);
|
|
185
203
|
const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
|
|
186
204
|
str += `${spaces} ${stringedKey}: `;
|
|
187
205
|
if ((0, import_types.isArray)(value)) {
|
package/dist/cjs/string.js
CHANGED
|
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var string_exports = {};
|
|
20
20
|
__export(string_exports, {
|
|
21
21
|
replaceLiteralsWithObjectFields: () => replaceLiteralsWithObjectFields,
|
|
22
|
-
stringIncludesAny: () => stringIncludesAny
|
|
22
|
+
stringIncludesAny: () => stringIncludesAny,
|
|
23
|
+
trimStringFromSymbols: () => trimStringFromSymbols
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(string_exports);
|
|
25
26
|
const stringIncludesAny = (str, characters) => {
|
|
@@ -30,6 +31,10 @@ const stringIncludesAny = (str, characters) => {
|
|
|
30
31
|
}
|
|
31
32
|
return false;
|
|
32
33
|
};
|
|
34
|
+
const trimStringFromSymbols = (str, characters) => {
|
|
35
|
+
const pattern = new RegExp(`[${characters.join("\\")}]`, "g");
|
|
36
|
+
return str.replace(pattern, "");
|
|
37
|
+
};
|
|
33
38
|
const brackRegex = /\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}/g;
|
|
34
39
|
const replaceLiteralsWithObjectFields = (str, state) => {
|
|
35
40
|
if (!str.includes("{{"))
|
package/object.js
CHANGED
|
@@ -111,6 +111,22 @@ export const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
|
|
|
111
111
|
}
|
|
112
112
|
return o
|
|
113
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Deep cloning of object
|
|
116
|
+
*/
|
|
117
|
+
export const deepCloneWithExtnd = (obj, excludeFrom = [], cleanUndefined = false) => {
|
|
118
|
+
const o = isArray(obj) ? [] : {}
|
|
119
|
+
for (const prop in obj) {
|
|
120
|
+
if (prop === '__proto__') continue
|
|
121
|
+
if (excludeFrom.includes(prop) || prop.startsWith('__')) continue
|
|
122
|
+
const objProp = obj[prop]
|
|
123
|
+
if (cleanUndefined && isUndefined(objProp)) continue
|
|
124
|
+
if (isObjectLike(objProp)) {
|
|
125
|
+
o[prop] = deepClone(objProp, excludeFrom, cleanUndefined)
|
|
126
|
+
} else o[prop] = objProp
|
|
127
|
+
}
|
|
128
|
+
return o
|
|
129
|
+
}
|
|
114
130
|
|
|
115
131
|
/**
|
|
116
132
|
* Stringify object
|
|
@@ -147,7 +163,7 @@ export const objectToString = (obj, indent = 0) => {
|
|
|
147
163
|
let str = '{\n'
|
|
148
164
|
|
|
149
165
|
for (const [key, value] of Object.entries(obj)) {
|
|
150
|
-
const keyNotAllowdChars = stringIncludesAny(key, ['-', ':', '@', '.', '/', '!'])
|
|
166
|
+
const keyNotAllowdChars = stringIncludesAny(key, ['&', '*', '-', ':', '@', '.', '/', '!', ' '])
|
|
151
167
|
const stringedKey = keyNotAllowdChars ? `'${key}'` : key
|
|
152
168
|
str += `${spaces} ${stringedKey}: `
|
|
153
169
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.38",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"build": "yarn build:cjs",
|
|
24
24
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "58e7232b8f8553780368bc463000766575565816",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|
package/string.js
CHANGED
|
@@ -8,6 +8,15 @@ export const stringIncludesAny = (str, characters) => {
|
|
|
8
8
|
}
|
|
9
9
|
return false
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
export const trimStringFromSymbols = (str, characters) => {
|
|
13
|
+
// Create a regular expression pattern to match the specified symbols
|
|
14
|
+
const pattern = new RegExp(`[${characters.join('\\')}]`, 'g')
|
|
15
|
+
|
|
16
|
+
// Replace matched symbols with an empty string
|
|
17
|
+
return str.replace(pattern, '')
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
/**
|
|
12
21
|
* Replaces placeholders in a string with corresponding {{ }} values from an object.
|
|
13
22
|
*
|