Projekt

Obecné

Profil

Stáhnout (745 Bajtů) Statistiky
| Větev: | Revize:
1
/* eslint-disable
2
  strict,
3
  no-param-reassign
4
*/
5

    
6
'use strict';
7

    
8
const fs = require('fs');
9
const path = require('path');
10

    
11
const Ajv = require('ajv');
12
const errors = require('ajv-errors');
13
const keywords = require('ajv-keywords');
14

    
15
const ValidationError = require('./ValidationError');
16

    
17
const ajv = new Ajv({
18
  allErrors: true,
19
  jsonPointers: true,
20
});
21

    
22
errors(ajv);
23
keywords(ajv, ['instanceof', 'typeof']);
24

    
25
const validateOptions = (schema, options, name) => {
26
  if (typeof schema === 'string') {
27
    schema = fs.readFileSync(path.resolve(schema), 'utf8');
28
    schema = JSON.parse(schema);
29
  }
30

    
31
  if (!ajv.validate(schema, options)) {
32
    throw new ValidationError(ajv.errors, name);
33
  }
34

    
35
  return true;
36
};
37

    
38
module.exports = validateOptions;
(3-3/3)