UNPKG

766 BJavaScriptView Raw
1var env = require('jjv')()
2var schema = require('./schema.json')
3
4var CCCFException = function(message, trace) {
5 this.message = message
6 this.trace = trace
7 this.toString = function() {
8 return this.message + '. Details in e.trace.'
9 }
10}
11
12env.addSchema('cccf', schema)
13env.addSchema('cccf-multiple', {
14 type : 'array',
15 items : {
16 '$ref' : "#/definitions/cccf"
17 },
18 definitions : {
19 "cccf" : schema
20 }
21})
22
23module.exports = {
24 schema : schema,
25 validate : function(config) {
26 if (!(typeof config == 'object')) config = JSON.parse(config)
27 var _config = (config instanceof Array) ? config : [config]
28 var err = env.validate('cccf-multiple', _config)
29 if (err) throw new CCCFException('Invalid config', err)
30 return config
31 },
32 exception : CCCFException
33}
\No newline at end of file