forked from zhanglei923/rk-offlinedev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.js
31 lines (30 loc) · 958 Bytes
/
validator.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
let fs = require('fs')
var validate_reviewer = require('./reviewers/validate_reviewer')
var betajson_reviewer = require('./reviewers/betajson_reviewer')
var widgets_reviewer = require('./reviewers/widgets_reviewer')
let thisUtil = {
validate:(jsonString)=>{
var errors = [];
let json;
try{
json = JSON.parse(jsonString);
}catch(e){
console.log(e);
}
if(!json) {
errors.push({
level: 'fatal',
errorType: 'not_json',
errorMsg: '不是json字符串'
})
return errors;
}
if(json.config) json = json.config;
json = [json]
errors = errors.concat(validate_reviewer.check(json));
errors = errors.concat(betajson_reviewer.check(json));
errors = errors.concat(widgets_reviewer.check(json));
return errors;
}
}
module.exports = thisUtil;