typed-ocpp
Version:
A library for type-aware parsing, serialization and validation of OCPP 1.6, OCPP 2.0 and OCPP 2.1 messages
20 lines • 615 B
JavaScript
import Ajv from 'ajv';
import addFormats from 'ajv-formats';
import { EMPTY_ARR } from './utils.js';
const ajv = addFormats(new Ajv({
strict: false,
multipleOfPrecision: 3,
removeAdditional: true,
}));
export const validate = Object.assign((value, schema, prefix) => {
if (ajv.validate(schema, value)) {
validate.errors = EMPTY_ARR;
return true;
}
validate.errors = ajv.errors.map((e) => `${prefix}: ${e.instancePath} ${e.message}`);
return false;
}, { errors: EMPTY_ARR });
export const compile = (schema) => {
ajv.compile(schema);
};
//# sourceMappingURL=ajv.js.map