UNPKG

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

Version:

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

80 lines (68 loc) 4.86 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _validatorFunctions = require("../validators/validator-functions"); var _urlValidator = _interopRequireDefault(require("../validators/url-validator")); var _validatorTypes = _interopRequireDefault(require("../validator-types")); var _validatorMapper; var _excluded = ["threshold"], _excluded2 = ["threshold"], _excluded3 = ["threshold"], _excluded4 = ["threshold"], _excluded5 = ["value", "includeThreshold"], _excluded6 = ["value", "includeThreshold"], _excluded7 = ["message"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } var validatorMapper = (_validatorMapper = {}, (0, _defineProperty2["default"])(_validatorMapper, _validatorTypes["default"].REQUIRED, _validatorFunctions.required), (0, _defineProperty2["default"])(_validatorMapper, _validatorTypes["default"].MIN_LENGTH, function (_ref) { var threshold = _ref.threshold, rest = (0, _objectWithoutProperties2["default"])(_ref, _excluded); return (0, _validatorFunctions.length)(_objectSpread({ minimum: threshold }, rest)); }), (0, _defineProperty2["default"])(_validatorMapper, _validatorTypes["default"].MAX_LENGTH, function (_ref2) { var threshold = _ref2.threshold, rest = (0, _objectWithoutProperties2["default"])(_ref2, _excluded2); return (0, _validatorFunctions.length)(_objectSpread({ maximum: threshold }, rest)); }), (0, _defineProperty2["default"])(_validatorMapper, _validatorTypes["default"].EXACT_LENGTH, function (_ref3) { var threshold = _ref3.threshold, rest = (0, _objectWithoutProperties2["default"])(_ref3, _excluded3); return (0, _validatorFunctions.length)(_objectSpread({ is: threshold }, rest)); }), (0, _defineProperty2["default"])(_validatorMapper, _validatorTypes["default"].MIN_ITEMS, function (_ref4) { var threshold = _ref4.threshold, rest = (0, _objectWithoutProperties2["default"])(_ref4, _excluded4); return (0, _validatorFunctions.length)(_objectSpread({ minimum: threshold, message: "Must have at least ".concat(threshold, " items.") }, rest)); }), (0, _defineProperty2["default"])(_validatorMapper, _validatorTypes["default"].PATTERN, _validatorFunctions.pattern), (0, _defineProperty2["default"])(_validatorMapper, _validatorTypes["default"].MAX_NUMBER_VALUE, function (_ref5) { var value = _ref5.value, _ref5$includeThreshol = _ref5.includeThreshold, includeThreshold = _ref5$includeThreshol === void 0 ? true : _ref5$includeThreshol, rest = (0, _objectWithoutProperties2["default"])(_ref5, _excluded5); return (0, _validatorFunctions.numericality)(_objectSpread((0, _defineProperty2["default"])({}, includeThreshold ? '<=' : '<', value), rest)); }), (0, _defineProperty2["default"])(_validatorMapper, _validatorTypes["default"].MIN_NUMBER_VALUE, function (_ref6) { var value = _ref6.value, _ref6$includeThreshol = _ref6.includeThreshold, includeThreshold = _ref6$includeThreshol === void 0 ? true : _ref6$includeThreshol, rest = (0, _objectWithoutProperties2["default"])(_ref6, _excluded6); return (0, _validatorFunctions.numericality)(_objectSpread((0, _defineProperty2["default"])({}, includeThreshold ? '>=' : '>', value), rest)); }), (0, _defineProperty2["default"])(_validatorMapper, _validatorTypes["default"].URL, function (_ref7) { var message = _ref7.message, options = (0, _objectWithoutProperties2["default"])(_ref7, _excluded7); return (0, _validatorFunctions.pattern)({ pattern: (0, _urlValidator["default"])(options), message: message || 'String is not URL.' }); }), _validatorMapper); var _default = validatorMapper; exports["default"] = _default;