UNPKG

@data-driven-forms/react-form-renderer

Version:

React Form Renderer. Data Driven Forms converts JSON form definitions into fully functional React forms.

62 lines 2.99 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var _a; import { required, length, pattern, numericality } from '../validators/validator-functions'; import url from '../validators/url-validator'; import validatorTypes from '../validator-types'; var validatorMapper = (_a = {}, _a[validatorTypes.REQUIRED] = required, _a[validatorTypes.MIN_LENGTH] = function (_a) { var threshold = _a.threshold, rest = __rest(_a, ["threshold"]); return length(__assign({ minimum: threshold }, rest)); }, _a[validatorTypes.MAX_LENGTH] = function (_a) { var threshold = _a.threshold, rest = __rest(_a, ["threshold"]); return length(__assign({ maximum: threshold }, rest)); }, _a[validatorTypes.EXACT_LENGTH] = function (_a) { var threshold = _a.threshold, rest = __rest(_a, ["threshold"]); return length(__assign({ is: threshold }, rest)); }, _a[validatorTypes.MIN_ITEMS] = function (_a) { var threshold = _a.threshold, rest = __rest(_a, ["threshold"]); return length(__assign({ minimum: threshold, message: "Must have at least ".concat(threshold, " items.") }, rest)); }, _a[validatorTypes.PATTERN] = pattern, _a[validatorTypes.MAX_NUMBER_VALUE] = function (_a) { var _b; var value = _a.value, _c = _a.includeThreshold, includeThreshold = _c === void 0 ? true : _c, rest = __rest(_a, ["value", "includeThreshold"]); return numericality(__assign((_b = {}, _b[includeThreshold ? '<=' : '<'] = value, _b), rest)); }, _a[validatorTypes.MIN_NUMBER_VALUE] = function (_a) { var _b; var value = _a.value, _c = _a.includeThreshold, includeThreshold = _c === void 0 ? true : _c, rest = __rest(_a, ["value", "includeThreshold"]); return numericality(__assign((_b = {}, _b[includeThreshold ? '>=' : '>'] = value, _b), rest)); }, _a[validatorTypes.URL] = function (_a) { var message = _a.message, options = __rest(_a, ["message"]); return pattern({ pattern: url(options), message: message || 'String is not URL.' }); }, _a); export default validatorMapper; //# sourceMappingURL=validator-mapper.js.map