UNPKG

web-components

Version:

Build and Test React Components in real time

48 lines (32 loc) 1.09 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getValidation; var _joi = require('joi'); var _joi2 = _interopRequireDefault(_joi); var _lodash = require('lodash'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function getValidation() { var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (!(0, _lodash.isPlainObject)(schema)) { throw new Error('schema ' + schema + ' should be a plain object'); } return function () { var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if ((0, _lodash.isEmpty)(values)) { return {}; } var _Joi$validate = _joi2.default.validate(values, schema, { abortEarly: false }); var error = _Joi$validate.error; if (!error) { return {}; } var errors = {}; error.details.forEach(function (detail) { errors[detail.path] = detail.message; }); return errors; }; } //# sourceMappingURL=getValidation.js.map