mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-16 10:15:18 +00:00
Merge pull request #21947 from DEV-DIBSTER/main
chore: create testing file
This commit is contained in:
1 file changed
+35
-19
+35
-19
@@ -36,30 +36,46 @@ const domainsPath = path.resolve("domains");
|
|||||||
const files = fs.readdirSync(domainsPath);
|
const files = fs.readdirSync(domainsPath);
|
||||||
|
|
||||||
function findDuplicateKeys(jsonString) {
|
function findDuplicateKeys(jsonString) {
|
||||||
const duplicateKeys = [];
|
const duplicateKeys = new Set();
|
||||||
|
const keyStack = [];
|
||||||
|
|
||||||
const stack = [];
|
const keyRegex = /"(.*?)"\s*:/g;
|
||||||
|
|
||||||
const obj = JSON.parse(jsonString, (key, value) => {
|
let i = 0;
|
||||||
if (typeof key === "string") {
|
while (i < jsonString.length) {
|
||||||
const current = stack[stack.length - 1];
|
const char = jsonString[i];
|
||||||
if (current) {
|
|
||||||
if (current[key]) {
|
if (char === "{") {
|
||||||
duplicateKeys.push(key);
|
keyStack.push({});
|
||||||
} else {
|
i++;
|
||||||
current[key] = true;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (char === "}") {
|
||||||
|
keyStack.pop();
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyRegex.lastIndex = i;
|
||||||
|
const match = keyRegex.exec(jsonString);
|
||||||
|
if (match && match.index === i && keyStack.length > 0) {
|
||||||
|
const key = match[1];
|
||||||
|
const currentScope = keyStack[keyStack.length - 1];
|
||||||
|
|
||||||
|
if (currentScope[key]) {
|
||||||
|
duplicateKeys.add(key);
|
||||||
|
} else {
|
||||||
|
currentScope[key] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i = keyRegex.lastIndex;
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof value === "object" && value !== null) {
|
return [...duplicateKeys];
|
||||||
stack.push({});
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
});
|
|
||||||
|
|
||||||
return [...new Set(duplicateKeys)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function validateFields(t, obj, fields, file, prefix = "") {
|
async function validateFields(t, obj, fields, file, prefix = "") {
|
||||||
|
|||||||
Reference in new issue
Block a user