maplibre-gl
Version:
BSD licensed community fork of mapbox-gl, a WebGL interactive maps library
37 lines (32 loc) • 1.02 kB
text/typescript
import ValidationError from '../error/validation_error';
import getType from '../util/get_type';
import validate from './validate';
import validateNumber from './validate_number';
export default function validatePadding(options) {
const key = options.key;
const value = options.value;
const type = getType(value);
if (type === 'array') {
if (value.length < 1 || value.length > 4) {
return [new ValidationError(key, value, `padding requires 1 to 4 values; ${value.length} values found`)];
}
const arrayElementSpec = {
type: 'number'
};
let errors = [];
for (let i = 0; i < value.length; i++) {
errors = errors.concat(validate({
key: `${key}[${i}]`,
value: value[i],
valueSpec: arrayElementSpec
}));
}
return errors;
} else {
return validateNumber({
key,
value,
valueSpec: {}
});
}
}