78e5275605b0d2d5bb0f54d6c1e80b0c51df37e3c986f53c8abb24e53614b47301a63abc94636496ef9d2c81e5aa6a310fab931c22e43f7d54f02e41571492 728 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* eslint-disable
  2. strict,
  3. no-param-reassign
  4. */
  5. 'use strict';
  6. const fs = require('fs');
  7. const path = require('path');
  8. const Ajv = require('ajv');
  9. const ajvKeywords = require('ajv-keywords');
  10. const ValidationError = require('./ValidationError');
  11. const ajv = new Ajv({
  12. allErrors: true,
  13. useDefaults: true,
  14. errorDataPath: 'property',
  15. });
  16. ajvKeywords(ajv, ['instanceof', 'typeof']);
  17. const validateOptions = (schema, options, name) => {
  18. if (typeof schema === 'string') {
  19. schema = fs.readFileSync(path.resolve(schema), 'utf8');
  20. schema = JSON.parse(schema);
  21. }
  22. if (!ajv.validate(schema, options)) {
  23. throw new ValidationError(ajv.errors, name);
  24. }
  25. return true;
  26. };
  27. module.exports = validateOptions;