@domql/utils 2.5.97 → 2.5.100
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 +33 -0
- package/dist/cjs/string.js +13 -0
- package/object.js +40 -0
- package/package.json +2 -2
- package/string.js +13 -0
package/dist/cjs/object.js
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var object_exports = {};
|
|
20
20
|
__export(object_exports, {
|
|
21
|
+
checkIfKeyIsComponent: () => checkIfKeyIsComponent,
|
|
21
22
|
clone: () => clone,
|
|
22
23
|
createObjectWithoutPrototype: () => createObjectWithoutPrototype,
|
|
23
24
|
deepClone: () => deepClone,
|
|
@@ -33,6 +34,7 @@ __export(object_exports, {
|
|
|
33
34
|
diffArrays: () => diffArrays,
|
|
34
35
|
diffObjects: () => diffObjects,
|
|
35
36
|
exec: () => exec,
|
|
37
|
+
findExtendsInElement: () => findExtendsInElement,
|
|
36
38
|
flattenRecursive: () => flattenRecursive,
|
|
37
39
|
hasOwnProperty: () => hasOwnProperty,
|
|
38
40
|
isEmpty: () => isEmpty,
|
|
@@ -515,3 +517,34 @@ const createObjectWithoutPrototype = (obj) => {
|
|
|
515
517
|
}
|
|
516
518
|
return newObj;
|
|
517
519
|
};
|
|
520
|
+
const checkIfKeyIsComponent = (key) => {
|
|
521
|
+
const isFirstKeyString = (0, import_types.isString)(key);
|
|
522
|
+
if (!isFirstKeyString)
|
|
523
|
+
return;
|
|
524
|
+
const firstCharKey = key.slice(0, 1);
|
|
525
|
+
return /^[A-Z]*$/.test(firstCharKey);
|
|
526
|
+
};
|
|
527
|
+
const findExtendsInElement = (obj) => {
|
|
528
|
+
let result = [];
|
|
529
|
+
function traverse(o) {
|
|
530
|
+
for (const key in o) {
|
|
531
|
+
if (Object.hasOwnProperty.call(o, key)) {
|
|
532
|
+
if (checkIfKeyIsComponent(key)) {
|
|
533
|
+
result.push(key);
|
|
534
|
+
}
|
|
535
|
+
if (key === "extend") {
|
|
536
|
+
if (typeof o[key] === "string") {
|
|
537
|
+
result.push(o[key]);
|
|
538
|
+
} else if (Array.isArray(o[key])) {
|
|
539
|
+
result = result.concat(o[key]);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (typeof o[key] === "object" && o[key] !== null) {
|
|
543
|
+
traverse(o[key]);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
traverse(obj);
|
|
549
|
+
return result;
|
|
550
|
+
};
|
package/dist/cjs/string.js
CHANGED
|
@@ -18,6 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var string_exports = {};
|
|
20
20
|
__export(string_exports, {
|
|
21
|
+
customDecodeURIComponent: () => customDecodeURIComponent,
|
|
22
|
+
customEncodeURIComponent: () => customEncodeURIComponent,
|
|
21
23
|
findKeyPosition: () => findKeyPosition,
|
|
22
24
|
lowercaseFirstLetter: () => lowercaseFirstLetter,
|
|
23
25
|
replaceLiteralsWithObjectFields: () => replaceLiteralsWithObjectFields,
|
|
@@ -121,3 +123,14 @@ const replaceOctalEscapeSequences = (str) => {
|
|
|
121
123
|
return char;
|
|
122
124
|
});
|
|
123
125
|
};
|
|
126
|
+
const customEncodeURIComponent = (str) => {
|
|
127
|
+
return str.split("").map((char) => {
|
|
128
|
+
if (/[^a-zA-Z0-9\s]/.test(char)) {
|
|
129
|
+
return "%" + char.charCodeAt(0).toString(16).toUpperCase();
|
|
130
|
+
}
|
|
131
|
+
return char;
|
|
132
|
+
}).join("");
|
|
133
|
+
};
|
|
134
|
+
const customDecodeURIComponent = (encodedStr) => {
|
|
135
|
+
return encodedStr.replace(/%[0-9A-Fa-f]{2}/g, (match) => String.fromCharCode(parseInt(match.slice(1), 16)));
|
|
136
|
+
};
|
package/object.js
CHANGED
|
@@ -593,3 +593,43 @@ export const createObjectWithoutPrototype = (obj) => {
|
|
|
593
593
|
|
|
594
594
|
return newObj
|
|
595
595
|
}
|
|
596
|
+
|
|
597
|
+
export const checkIfKeyIsComponent = (key) => {
|
|
598
|
+
const isFirstKeyString = isString(key)
|
|
599
|
+
if (!isFirstKeyString) return
|
|
600
|
+
const firstCharKey = key.slice(0, 1)
|
|
601
|
+
return /^[A-Z]*$/.test(firstCharKey)
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
export const findExtendsInElement = (obj) => {
|
|
605
|
+
let result = []
|
|
606
|
+
|
|
607
|
+
function traverse (o) {
|
|
608
|
+
for (const key in o) {
|
|
609
|
+
if (Object.hasOwnProperty.call(o, key)) {
|
|
610
|
+
// Check if the key starts with a capital letter and exclude keys like @mobileL, $propsCollection
|
|
611
|
+
if (checkIfKeyIsComponent(key)) {
|
|
612
|
+
result.push(key)
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Check if the key is "extend" and it's either a string or an array
|
|
616
|
+
if (key === 'extend') {
|
|
617
|
+
// Add the value of the extend key to the result array
|
|
618
|
+
if (typeof o[key] === 'string') {
|
|
619
|
+
result.push(o[key])
|
|
620
|
+
} else if (Array.isArray(o[key])) {
|
|
621
|
+
result = result.concat(o[key])
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// If the property is an object, traverse it
|
|
626
|
+
if (typeof o[key] === 'object' && o[key] !== null) {
|
|
627
|
+
traverse(o[key])
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
traverse(obj)
|
|
634
|
+
return result
|
|
635
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.100",
|
|
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": "38b74a597edc2f9454a81b892505282a944fd5b9",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|
package/string.js
CHANGED
|
@@ -124,3 +124,16 @@ export const replaceOctalEscapeSequences = (str) => {
|
|
|
124
124
|
return char
|
|
125
125
|
})
|
|
126
126
|
}
|
|
127
|
+
|
|
128
|
+
export const customEncodeURIComponent = (str) => {
|
|
129
|
+
return str.split('').map(char => {
|
|
130
|
+
if (/[^a-zA-Z0-9\s]/.test(char)) {
|
|
131
|
+
return '%' + char.charCodeAt(0).toString(16).toUpperCase()
|
|
132
|
+
}
|
|
133
|
+
return char
|
|
134
|
+
}).join('')
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const customDecodeURIComponent = (encodedStr) => {
|
|
138
|
+
return encodedStr.replace(/%[0-9A-Fa-f]{2}/g, match => String.fromCharCode(parseInt(match.slice(1), 16)))
|
|
139
|
+
}
|