@domql/utils 2.5.94 → 2.5.97
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 +13 -0
- package/dist/cjs/array.js +12 -0
- package/dist/cjs/object.js +13 -0
- package/dist/cjs/string.js +56 -0
- package/object.js +16 -0
- package/package.json +2 -2
- package/string.js +70 -0
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
|
+
};
|
package/dist/cjs/object.js
CHANGED
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var object_exports = {};
|
|
20
20
|
__export(object_exports, {
|
|
21
21
|
clone: () => clone,
|
|
22
|
+
createObjectWithoutPrototype: () => createObjectWithoutPrototype,
|
|
22
23
|
deepClone: () => deepClone,
|
|
23
24
|
deepCloneExclude: () => deepCloneExclude,
|
|
24
25
|
deepCloneWithExtend: () => deepCloneWithExtend,
|
|
@@ -502,3 +503,15 @@ const removeFromObject = (obj, props) => {
|
|
|
502
503
|
}
|
|
503
504
|
return obj;
|
|
504
505
|
};
|
|
506
|
+
const createObjectWithoutPrototype = (obj) => {
|
|
507
|
+
if (obj === null || typeof obj !== "object") {
|
|
508
|
+
return obj;
|
|
509
|
+
}
|
|
510
|
+
const newObj = /* @__PURE__ */ Object.create(null);
|
|
511
|
+
for (const key in obj) {
|
|
512
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
513
|
+
newObj[key] = createObjectWithoutPrototype(obj[key]);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return newObj;
|
|
517
|
+
};
|
package/dist/cjs/string.js
CHANGED
|
@@ -18,8 +18,10 @@ 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
|
+
findKeyPosition: () => findKeyPosition,
|
|
21
22
|
lowercaseFirstLetter: () => lowercaseFirstLetter,
|
|
22
23
|
replaceLiteralsWithObjectFields: () => replaceLiteralsWithObjectFields,
|
|
24
|
+
replaceOctalEscapeSequences: () => replaceOctalEscapeSequences,
|
|
23
25
|
stringIncludesAny: () => stringIncludesAny,
|
|
24
26
|
trimStringFromSymbols: () => trimStringFromSymbols
|
|
25
27
|
});
|
|
@@ -65,3 +67,57 @@ const replaceLiteralsWithObjectFields = (str, state, options = {}) => {
|
|
|
65
67
|
const lowercaseFirstLetter = (inputString) => {
|
|
66
68
|
return `${inputString.charAt(0).toLowerCase()}${inputString.slice(1)}`;
|
|
67
69
|
};
|
|
70
|
+
const findKeyPosition = (str, key) => {
|
|
71
|
+
const lines = str.split("\n");
|
|
72
|
+
let startLineNumber = -1;
|
|
73
|
+
let endLineNumber = -1;
|
|
74
|
+
let startColumn = -1;
|
|
75
|
+
let endColumn = -1;
|
|
76
|
+
const keyPattern = new RegExp(`\\b${key}\\b\\s*:\\s*`);
|
|
77
|
+
let braceCount = 0;
|
|
78
|
+
let foundKey = false;
|
|
79
|
+
for (let i = 0; i < lines.length; i++) {
|
|
80
|
+
if (keyPattern.test(lines[i]) && !foundKey) {
|
|
81
|
+
foundKey = true;
|
|
82
|
+
startLineNumber = i + 1;
|
|
83
|
+
startColumn = lines[i].indexOf(key) + 1;
|
|
84
|
+
if (lines[i].includes("{}")) {
|
|
85
|
+
endLineNumber = startLineNumber;
|
|
86
|
+
endColumn = lines[i].indexOf("{}") + 3;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
const line = lines[i].slice(startColumn + key.length);
|
|
90
|
+
if (line.includes("{") || line.includes("[")) {
|
|
91
|
+
braceCount = 1;
|
|
92
|
+
} else {
|
|
93
|
+
endLineNumber = i + 1;
|
|
94
|
+
endColumn = lines[i].length + 1;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
} else if (foundKey) {
|
|
98
|
+
braceCount += (lines[i].match(/{/g) || []).length;
|
|
99
|
+
braceCount += (lines[i].match(/\[/g) || []).length;
|
|
100
|
+
braceCount -= (lines[i].match(/}/g) || []).length;
|
|
101
|
+
braceCount -= (lines[i].match(/]/g) || []).length;
|
|
102
|
+
if (braceCount === 0) {
|
|
103
|
+
endLineNumber = i + 1;
|
|
104
|
+
endColumn = lines[i].lastIndexOf("}") !== -1 ? lines[i].lastIndexOf("}") + 2 : lines[i].length + 1;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
startColumn,
|
|
111
|
+
endColumn,
|
|
112
|
+
startLineNumber,
|
|
113
|
+
endLineNumber
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
const replaceOctalEscapeSequences = (str) => {
|
|
117
|
+
const octalRegex = /\\([0-7]{1,3})/g;
|
|
118
|
+
return str.replace(octalRegex, (match, p1) => {
|
|
119
|
+
const octalValue = parseInt(p1, 8);
|
|
120
|
+
const char = String.fromCharCode(octalValue);
|
|
121
|
+
return char;
|
|
122
|
+
});
|
|
123
|
+
};
|
package/object.js
CHANGED
|
@@ -577,3 +577,19 @@ export const removeFromObject = (obj, props) => {
|
|
|
577
577
|
}
|
|
578
578
|
return obj
|
|
579
579
|
}
|
|
580
|
+
|
|
581
|
+
export const createObjectWithoutPrototype = (obj) => {
|
|
582
|
+
if (obj === null || typeof obj !== 'object') {
|
|
583
|
+
return obj // Return the value if obj is not an object
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
const newObj = Object.create(null) // Create an object without prototype
|
|
587
|
+
|
|
588
|
+
for (const key in obj) {
|
|
589
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
590
|
+
newObj[key] = createObjectWithoutPrototype(obj[key]) // Recursively copy each property
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
return newObj
|
|
595
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.97",
|
|
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": "0dd6029804289092faf4f94a4b853486233baf34",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|
package/string.js
CHANGED
|
@@ -54,3 +54,73 @@ 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
|
+
}
|