2020-06-23 16:31:16 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
2020-06-18 18:10:12 +02:00
|
|
|
const checkFieldsAreCorrectlyNested = fields => {
|
2020-06-23 16:31:16 +02:00
|
|
|
if (_.isNil(fields)) {
|
2020-06-22 13:00:21 +02:00
|
|
|
// Only check if the fields exist
|
2020-06-18 11:40:50 +02:00
|
|
|
return true;
|
2020-06-23 16:31:16 +02:00
|
|
|
} else if (!Array.isArray(fields)) {
|
|
|
|
return false;
|
2020-06-18 11:40:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let failed = false;
|
|
|
|
for (let indexA = 0; indexA < fields.length; indexA++) {
|
|
|
|
failed = fields
|
|
|
|
.slice(indexA + 1)
|
2020-07-01 11:51:37 +02:00
|
|
|
.some(
|
|
|
|
fieldB => fieldB.startsWith(`${fields[indexA]}.`) || fields[indexA].startsWith(`${fieldB}.`)
|
|
|
|
);
|
2020-06-18 11:40:50 +02:00
|
|
|
if (failed) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !failed;
|
|
|
|
};
|
|
|
|
|
2020-06-18 18:10:12 +02:00
|
|
|
module.exports = checkFieldsAreCorrectlyNested;
|