UNPKG

519 BJavaScriptView Raw
1const Ajv = require('ajv')
2const {schema} = require('./schema')
3const {extglobFormat} = require('./format-extglob')
4
5const ajv = new Ajv({format: 'full'})
6ajv.addFormat('extglob', extglobFormat)
7ajv.addSchema(schema)
8
9module.exports.validate =
10function validate (json) {
11 const validity = ajv.validate('/Manifest', json)
12 if (validity === true) {
13 return true
14 } else {
15 const last = ajv.errors.pop()
16 const message = `${last.dataPath} ${last.message} ${last.schemaPath}`
17 throw new Error(message)
18 }
19}