UNPKG

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

Version:

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

67 lines (52 loc) 2.68 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _validators = _interopRequireDefault(require("../validators")); var _helpers = require("../common/helpers"); // user:pass BasicAuth (optional) var BASIC_AUTH = '(?:\\S+(?::\\S*)?@)?'; // IP address dotted notation octets var IPV4 = '(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)'; // the IPv6 matching part is from here: https://gist.github.com/syzdek/6086792 var IPV6 = '((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*::((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*|((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4})){7}|::1|1::'; // eslint-disable-line max-len // host & domain names, may end with dot var HOST = // can be replaced by // '(?:(?:[a-z0-9\\u00a1-\\uffff][a-z0-9\\u00a1-\\uffff_-]{0,62})?[a-z0-9\\u00a1-\\uffff]\\.)+' + "(?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+" + // TLD identifier name, may end with dot "(?:[a-z\\u00a1-\\uffff]{2,}\\.?)"; // port number (optional) var PORT = '(?::\\d{2,5})?'; // resource path (optional) var PATH = '(?:[/][^\\s?#]*)?'; var SEARCH = '(?:[?][^\\s#]*)?'; var HASH = '(?:[#]\\S*)?'; var DEFAULT_OPTIONS = { emptyProtocol: true, protocolIdentifier: true, basicAuth: true, local: true, ipv4: true, ipv6: true, host: true, port: true, path: true, search: true, hash: true }; var url = function url(options) { return buildReg(defaultOptions(options), false); }; var _default = url; exports["default"] = _default; function defaultOptions(options) { options = (0, _helpers.assign)({}, DEFAULT_OPTIONS, options); options.protocols = [].concat(options.protocol || options.protocols || _validators["default"].urlProtocols).join('|'); return options; } function group(option, regPart, capture) { return option ? capture ? "(".concat(regPart, ")") : regPart : ''; } function buildReg(options, capture) { return new RegExp('^' + group(true, "(?:(?:(?:".concat(options.protocols, "):)").concat(options.emptyProtocol ? '?' : '', "\\/\\/)").concat(options.protocolIdentifier ? '' : '?'), capture) + group(options.basicAuth, BASIC_AUTH, capture) + "(?:".concat([group(options.ipv4, IPV4, capture), group(options.ipv6, IPV6, capture), group(options.host, HOST, capture), group(options.local, 'localhost', capture)].filter(function (g) { return g; }).join('|'), ")") + group(options.port, PORT, capture) + group(options.path, PATH, capture) + group(options.search, SEARCH, capture) + group(options.hash, HASH, capture) + '$', 'i'); }