Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 1x 64x 64x 14x 64x 64x 108x 64x 64x 1x 64x 1x | const validateValueByRule = require('./validate-value-by-rule');
function validateValuesByRule(key, values, rule) {
let { property } = rule;
if (rule.type === 'percent') {
property = property || 'percent';
}
const errors = [];
const reducedValues = values.reduce(
(memo, value) => validateValueByRule(memo, value, key, property, rule),
{ errors: [], percentTotal: 0 },
);
errors.push(...reducedValues.errors);
if (
reducedValues.percentTotal !== 0
&& reducedValues.percentTotal !== 100
) {
errors.push(new Error(`percent properties "${property}" in values do not add up to 100 for key "${key}"`));
}
return errors;
}
module.exports = validateValuesByRule;
|