@deskpro/react-forms
Version:
Forms library for React
27 lines (22 loc) • 779 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = JSONSchema;
var _compileValidator = require('./compileValidator');
var _compileValidator2 = _interopRequireDefault(_compileValidator);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Create a JSON schema validator which returns a list of errors for invalid
* objects and an empty list of errors for valid objects.
*/
function JSONSchema(schema, options) {
var validate = (0, _compileValidator2.default)(schema, options);
return function validator(obj) {
var result = validate(obj);
var errors = validate.errors;
return result ? [] : errors;
};
} /**
* @copyright 2015, Prometheus Research, LLC
*/