strapi/packages/strapi-admin/validation/common-functions/check-fields-are-correctly-nested.js
Pierre Noël 8598cee8d0 fourth refacto
Signed-off-by: Pierre Noël <petersg83@gmail.com>
2020-07-08 11:09:52 +02:00

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;