Merge pull request #1086 from jameslcj/feature/yaml

feature: add yaml validator #1084
This commit is contained in:
Fury Zhu 2019-06-10 16:57:11 +08:00 committed by GitHub
commit 696312a33c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 20 deletions

View File

@ -38,6 +38,9 @@ module.exports = {
components: resolve('src/components'),
},
},
node: {
fs: 'empty'
},
module: {
rules: [
{

View File

@ -75,6 +75,7 @@
"react-router-dom": "^4.3.1",
"react-router-redux": "^4.0.8",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
"redux-thunk": "^2.3.0",
"yamljs": "^0.3.0"
}
}

View File

@ -1,3 +1,5 @@
import * as yamljs from 'yamljs';
export default {
/**
* 检测json是否合法
@ -35,15 +37,13 @@ export default {
/**
* 检测yaml是否合法
*/
// validateYaml(str) {
// try {
// console.log('yaml: ', yaml, yaml.safeLoadAll(str));
// return !!yaml.safeLoadAll(str);
// } catch (e) {
// console.log('e: ', e);
// return false;
// }
// },
validateYaml(str) {
try {
return yamljs.parse(str);
} catch (e) {
return false;
}
},
/**
* 检测属性是否正确
@ -66,6 +66,7 @@ export default {
'text/html': this.validateXml,
html: this.validateXml,
properties: this.validateProperties,
yaml: this.validateYaml,
};
if (!validateObj[type]) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long