-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (40 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var env = require('jjv')()
var assign = require('object.assign')
var utils = require('./utils')
var schema = require('./schema.json')
var ZNFException = function(message, trace) {
this.message = message
this.trace = trace
this.toString = function() {
return this.message + '. Details in e.trace.'
}
}
env.addSchema('znf', schema)
env.addSchema('znf-multiple', {
type : 'array',
items : {
'$ref' : "#/definitions/znf"
},
definitions : {
"znf" : schema
}
})
module.exports = {
schema : schema,
validate : function(config) {
if (!(typeof config == 'object')) config = JSON.parse(config)
var _config = (config instanceof Array) ? config : [config]
var err = env.validate('znf-multiple', _config)
if (err) throw new ZNFException('Invalid config', err)
return config
},
exception : ZNFException,
random: function(num, opts) {
opts = opts || {}
return Array.apply(null, {length: num}).map(function(value, index){
var c = utils.randomExampleNode()
assign(c, opts)
return c
})
}
}