mirror of
https://github.com/strapi/strapi.git
synced 2025-08-11 18:27:22 +00:00
19 lines
461 B
JavaScript
19 lines
461 B
JavaScript
const checkFieldsAreCorrectlyNested = fields => {
|
|
if (!Array.isArray(fields)) {
|
|
// Only check if the fields exist
|
|
return true;
|
|
}
|
|
|
|
let failed = false;
|
|
for (let indexA = 0; indexA < fields.length; indexA++) {
|
|
failed = fields
|
|
.slice(indexA + 1)
|
|
.some(fieldB => fieldB.startsWith(fields[indexA]) || fields[indexA].startsWith(fieldB));
|
|
if (failed) break;
|
|
}
|
|
|
|
return !failed;
|
|
};
|
|
|
|
module.exports = checkFieldsAreCorrectlyNested;
|