初始化代码
This commit is contained in:
30
uniapp/uni-app/node_modules/schema-utils/src/ValidationError.js
generated
vendored
Normal file
30
uniapp/uni-app/node_modules/schema-utils/src/ValidationError.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/* eslint-disable
|
||||
strict,
|
||||
no-param-reassign
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
class ValidationError extends Error {
|
||||
constructor(errors, name) {
|
||||
super();
|
||||
|
||||
this.name = 'ValidationError';
|
||||
|
||||
this.message = `${name || ''} Invalid Options\n\n`;
|
||||
|
||||
this.errors = errors.map((err) => {
|
||||
err.dataPath = err.dataPath.replace(/\//g, '.');
|
||||
|
||||
return err;
|
||||
});
|
||||
|
||||
this.errors.forEach((err) => {
|
||||
this.message += `options${err.dataPath} ${err.message}\n`;
|
||||
});
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ValidationError;
|
||||
9
uniapp/uni-app/node_modules/schema-utils/src/index.js
generated
vendored
Normal file
9
uniapp/uni-app/node_modules/schema-utils/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/* eslint-disable
|
||||
strict
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const validateOptions = require('./validateOptions');
|
||||
|
||||
module.exports = validateOptions;
|
||||
38
uniapp/uni-app/node_modules/schema-utils/src/validateOptions.js
generated
vendored
Normal file
38
uniapp/uni-app/node_modules/schema-utils/src/validateOptions.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/* eslint-disable
|
||||
strict,
|
||||
no-param-reassign
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const Ajv = require('ajv');
|
||||
const errors = require('ajv-errors');
|
||||
const keywords = require('ajv-keywords');
|
||||
|
||||
const ValidationError = require('./ValidationError');
|
||||
|
||||
const ajv = new Ajv({
|
||||
allErrors: true,
|
||||
jsonPointers: true,
|
||||
});
|
||||
|
||||
errors(ajv);
|
||||
keywords(ajv, ['instanceof', 'typeof']);
|
||||
|
||||
const validateOptions = (schema, options, name) => {
|
||||
if (typeof schema === 'string') {
|
||||
schema = fs.readFileSync(path.resolve(schema), 'utf8');
|
||||
schema = JSON.parse(schema);
|
||||
}
|
||||
|
||||
if (!ajv.validate(schema, options)) {
|
||||
throw new ValidationError(ajv.errors, name);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = validateOptions;
|
||||
Reference in New Issue
Block a user