@domql/utils 2.5.95 → 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/array.js CHANGED
@@ -130,3 +130,16 @@ export const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
130
130
  }
131
131
  return newArray
132
132
  }
133
+ export const arraysEqual = (arr1, arr2) => {
134
+ if (arr1.length !== arr2.length) {
135
+ return false
136
+ }
137
+
138
+ for (let i = 0; i < arr1.length; i++) {
139
+ if (arr1[i] !== arr2[i]) {
140
+ return false
141
+ }
142
+ }
143
+
144
+ return true
145
+ }
package/dist/cjs/array.js CHANGED
@@ -20,6 +20,7 @@ var array_exports = {};
20
20
  __export(array_exports, {
21
21
  addItemAfterEveryElement: () => addItemAfterEveryElement,
22
22
  arrayContainsOtherArray: () => arrayContainsOtherArray,
23
+ arraysEqual: () => arraysEqual,
23
24
  createNestedObject: () => createNestedObject,
24
25
  cutArrayAfterValue: () => cutArrayAfterValue,
25
26
  cutArrayBeforeValue: () => cutArrayBeforeValue,
@@ -136,3 +137,14 @@ const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
136
137
  }
137
138
  return newArray;
138
139
  };
140
+ const arraysEqual = (arr1, arr2) => {
141
+ if (arr1.length !== arr2.length) {
142
+ return false;
143
+ }
144
+ for (let i = 0; i < arr1.length; i++) {
145
+ if (arr1[i] !== arr2[i]) {
146
+ return false;
147
+ }
148
+ }
149
+ return true;
150
+ };
@@ -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
+ };
@@ -18,8 +18,12 @@ 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,
23
+ findKeyPosition: () => findKeyPosition,
21
24
  lowercaseFirstLetter: () => lowercaseFirstLetter,
22
25
  replaceLiteralsWithObjectFields: () => replaceLiteralsWithObjectFields,
26
+ replaceOctalEscapeSequences: () => replaceOctalEscapeSequences,
23
27
  stringIncludesAny: () => stringIncludesAny,
24
28
  trimStringFromSymbols: () => trimStringFromSymbols
25
29
  });
@@ -65,3 +69,68 @@ const replaceLiteralsWithObjectFields = (str, state, options = {}) => {
65
69
  const lowercaseFirstLetter = (inputString) => {
66
70
  return `${inputString.charAt(0).toLowerCase()}${inputString.slice(1)}`;
67
71
  };
72
+ const findKeyPosition = (str, key) => {
73
+ const lines = str.split("\n");
74
+ let startLineNumber = -1;
75
+ let endLineNumber = -1;
76
+ let startColumn = -1;
77
+ let endColumn = -1;
78
+ const keyPattern = new RegExp(`\\b${key}\\b\\s*:\\s*`);
79
+ let braceCount = 0;
80
+ let foundKey = false;
81
+ for (let i = 0; i < lines.length; i++) {
82
+ if (keyPattern.test(lines[i]) && !foundKey) {
83
+ foundKey = true;
84
+ startLineNumber = i + 1;
85
+ startColumn = lines[i].indexOf(key) + 1;
86
+ if (lines[i].includes("{}")) {
87
+ endLineNumber = startLineNumber;
88
+ endColumn = lines[i].indexOf("{}") + 3;
89
+ break;
90
+ }
91
+ const line = lines[i].slice(startColumn + key.length);
92
+ if (line.includes("{") || line.includes("[")) {
93
+ braceCount = 1;
94
+ } else {
95
+ endLineNumber = i + 1;
96
+ endColumn = lines[i].length + 1;
97
+ break;
98
+ }
99
+ } else if (foundKey) {
100
+ braceCount += (lines[i].match(/{/g) || []).length;
101
+ braceCount += (lines[i].match(/\[/g) || []).length;
102
+ braceCount -= (lines[i].match(/}/g) || []).length;
103
+ braceCount -= (lines[i].match(/]/g) || []).length;
104
+ if (braceCount === 0) {
105
+ endLineNumber = i + 1;
106
+ endColumn = lines[i].lastIndexOf("}") !== -1 ? lines[i].lastIndexOf("}") + 2 : lines[i].length + 1;
107
+ break;
108
+ }
109
+ }
110
+ }
111
+ return {
112
+ startColumn,
113
+ endColumn,
114
+ startLineNumber,
115
+ endLineNumber
116
+ };
117
+ };
118
+ const replaceOctalEscapeSequences = (str) => {
119
+ const octalRegex = /\\([0-7]{1,3})/g;
120
+ return str.replace(octalRegex, (match, p1) => {
121
+ const octalValue = parseInt(p1, 8);
122
+ const char = String.fromCharCode(octalValue);
123
+ return char;
124
+ });
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.95",
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": "8ac5f539ad4739c7baa30dd68cb7d6f94e70aa3c",
26
+ "gitHead": "38b74a597edc2f9454a81b892505282a944fd5b9",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  }
package/string.js CHANGED
@@ -54,3 +54,86 @@ export const replaceLiteralsWithObjectFields = (str, state, options = {}) => {
54
54
  export const lowercaseFirstLetter = (inputString) => {
55
55
  return `${inputString.charAt(0).toLowerCase()}${inputString.slice(1)}`
56
56
  }
57
+
58
+ export const findKeyPosition = (str, key) => {
59
+ const lines = str.split('\n')
60
+ let startLineNumber = -1
61
+ let endLineNumber = -1
62
+ let startColumn = -1
63
+ let endColumn = -1
64
+
65
+ const keyPattern = new RegExp(`\\b${key}\\b\\s*:\\s*`)
66
+ let braceCount = 0
67
+ let foundKey = false
68
+
69
+ for (let i = 0; i < lines.length; i++) {
70
+ if (keyPattern.test(lines[i]) && !foundKey) {
71
+ foundKey = true
72
+ startLineNumber = i + 1
73
+ startColumn = lines[i].indexOf(key) + 1
74
+
75
+ // Check if the value is an empty object
76
+ if (lines[i].includes('{}')) {
77
+ endLineNumber = startLineNumber
78
+ endColumn = lines[i].indexOf('{}') + 3
79
+ break
80
+ }
81
+
82
+ // Check if the value starts with '{' (object) or '[' (array)
83
+ const line = lines[i].slice(startColumn + key.length)
84
+ if (line.includes('{') || line.includes('[')) {
85
+ braceCount = 1
86
+ } else {
87
+ endLineNumber = i + 1
88
+ endColumn = lines[i].length + 1
89
+ break
90
+ }
91
+ } else if (foundKey) {
92
+ braceCount += (lines[i].match(/{/g) || []).length
93
+ braceCount += (lines[i].match(/\[/g) || []).length
94
+ braceCount -= (lines[i].match(/}/g) || []).length
95
+ braceCount -= (lines[i].match(/]/g) || []).length
96
+
97
+ // If braceCount is 0 and we find the end of the object/array
98
+ if (braceCount === 0) {
99
+ endLineNumber = i + 1
100
+ endColumn = lines[i].lastIndexOf('}') !== -1 ? lines[i].lastIndexOf('}') + 2 : lines[i].length + 1
101
+ break
102
+ }
103
+ }
104
+ }
105
+
106
+ return {
107
+ startColumn,
108
+ endColumn,
109
+ startLineNumber,
110
+ endLineNumber
111
+ }
112
+ }
113
+
114
+ export const replaceOctalEscapeSequences = (str) => {
115
+ // Regex to match octal escape sequences
116
+ const octalRegex = /\\([0-7]{1,3})/g
117
+
118
+ // Replace each match with the corresponding character
119
+ return str.replace(octalRegex, (match, p1) => {
120
+ // Convert the octal value to a decimal integer
121
+ const octalValue = parseInt(p1, 8)
122
+ // Convert the decimal value to the corresponding character
123
+ const char = String.fromCharCode(octalValue)
124
+ return char
125
+ })
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
+ }