-
Notifications
You must be signed in to change notification settings - Fork 60
/
validator.js
34 lines (32 loc) · 915 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
32
33
34
import { Validator } from 'jsonschema';
export default function configValidator(options) {
const validator = new Validator();
const schema = {
title: 'very-axios options schema validator',
type: 'object',
properties: {
tip: {
description: 'whether or not show tips when error ocurrs',
type: 'boolean',
},
tipFn: {
description: 'whether or not show tips when error ocurrs',
type: 'function',
},
lang: {
description: 'error msg language: zh-cn/en',
type: 'string',
enum: ['zh-cn', 'en'],
},
},
};
const { errors } = validator.validate(options, schema);
const hasError = errors.length > 0;
if (hasError) {
errors.forEach((err) => {
/* eslint-disable no-console */
console.error(`very-axios: ${err.property.split('instance.')[1]} ${err.message}`);
});
}
return hasError;
}