mirror of
https://github.com/strapi/strapi.git
synced 2025-08-11 18:27:22 +00:00
27 lines
584 B
JavaScript
27 lines
584 B
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
|
|
const checkFieldsAreCorrectlyNested = fields => {
|
|
if (_.isNil(fields)) {
|
|
// Only check if the fields exist
|
|
return true;
|
|
} else if (!Array.isArray(fields)) {
|
|
return false;
|
|
}
|
|
|
|
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;
|