You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

// @flow
import ValidationError from '../error/validation_error.js';
import getType from '../util/get_type.js';
import validate from './validate.js';
import type {ValidationOptions} from './validate.js';
export default function validateProjection(options: ValidationOptions): Array<ValidationError> {
const projection = options.value;
const styleSpec = options.styleSpec;
const projectionSpec = styleSpec.projection;
const style = options.style;
let errors = [];
const rootType = getType(projection);
if (rootType === 'object') {
for (const key in projection) {
errors = errors.concat(validate({
key,
value: projection[key],
valueSpec: projectionSpec[key],
style,
styleSpec
}));
}
} else if (rootType !== 'string') {
errors = errors.concat([new ValidationError('projection', projection, `object or string expected, ${rootType} found`)]);
}
return errors;
}