@domql/utils 2.5.97 → 2.5.101

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.
@@ -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,
@@ -34,6 +35,8 @@ __export(object_exports, {
34
35
  diffObjects: () => diffObjects,
35
36
  exec: () => exec,
36
37
  flattenRecursive: () => flattenRecursive,
38
+ getChildrenComponentsByKey: () => getChildrenComponentsByKey,
39
+ getExtendsInElement: () => getExtendsInElement,
37
40
  hasOwnProperty: () => hasOwnProperty,
38
41
  isEmpty: () => isEmpty,
39
42
  isEmptyObject: () => isEmptyObject,
@@ -515,3 +518,45 @@ const createObjectWithoutPrototype = (obj) => {
515
518
  }
516
519
  return newObj;
517
520
  };
521
+ const checkIfKeyIsComponent = (key) => {
522
+ const isFirstKeyString = (0, import_types.isString)(key);
523
+ if (!isFirstKeyString)
524
+ return;
525
+ const firstCharKey = key.slice(0, 1);
526
+ return /^[A-Z]*$/.test(firstCharKey);
527
+ };
528
+ const getChildrenComponentsByKey = (key, el) => {
529
+ if (key === el.key || el.__ref.__componentKey === key) {
530
+ return el;
531
+ }
532
+ if (el.extend) {
533
+ const foundString = (0, import_types.isString)(el.extend) && el.extend === key;
534
+ const foundInArray = (0, import_types.isArray)(el.extend) && el.extend.filter((v) => v === key).length;
535
+ if (foundString || foundInArray)
536
+ return el;
537
+ }
538
+ };
539
+ const getExtendsInElement = (obj) => {
540
+ let result = [];
541
+ function traverse(o) {
542
+ for (const key in o) {
543
+ if (Object.hasOwnProperty.call(o, key)) {
544
+ if (checkIfKeyIsComponent(key)) {
545
+ result.push(key);
546
+ }
547
+ if (key === "extend") {
548
+ if (typeof o[key] === "string") {
549
+ result.push(o[key]);
550
+ } else if (Array.isArray(o[key])) {
551
+ result = result.concat(o[key]);
552
+ }
553
+ }
554
+ if (typeof o[key] === "object" && o[key] !== null) {
555
+ traverse(o[key]);
556
+ }
557
+ }
558
+ }
559
+ }
560
+ traverse(obj);
561
+ return result;
562
+ };
@@ -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,57 @@ 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 getChildrenComponentsByKey = (key, el) => {
605
+ if (key === el.key || el.__ref.__componentKey === key) {
606
+ return el
607
+ }
608
+
609
+ // Check if the prop is "extend" and it's either a string or an array
610
+ if (el.extend) {
611
+ // Add the value of the extend key to the result array
612
+ const foundString = isString(el.extend) && el.extend === key
613
+ const foundInArray = isArray(el.extend) && el.extend.filter(v => v === key).length
614
+ if (foundString || foundInArray) return el
615
+ }
616
+ }
617
+
618
+ export const getExtendsInElement = (obj) => {
619
+ let result = []
620
+
621
+ function traverse (o) {
622
+ for (const key in o) {
623
+ if (Object.hasOwnProperty.call(o, key)) {
624
+ // Check if the key starts with a capital letter and exclude keys like @mobileL, $propsCollection
625
+ if (checkIfKeyIsComponent(key)) {
626
+ result.push(key)
627
+ }
628
+
629
+ // Check if the key is "extend" and it's either a string or an array
630
+ if (key === 'extend') {
631
+ // Add the value of the extend key to the result array
632
+ if (typeof o[key] === 'string') {
633
+ result.push(o[key])
634
+ } else if (Array.isArray(o[key])) {
635
+ result = result.concat(o[key])
636
+ }
637
+ }
638
+
639
+ // If the property is an object, traverse it
640
+ if (typeof o[key] === 'object' && o[key] !== null) {
641
+ traverse(o[key])
642
+ }
643
+ }
644
+ }
645
+ }
646
+
647
+ traverse(obj)
648
+ return result
649
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.97",
3
+ "version": "2.5.101",
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": "0dd6029804289092faf4f94a4b853486233baf34",
26
+ "gitHead": "5a5e8988f25e9a77e44596d9fd23e8a00b725685",
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
+ }