n4s
Version:
Assertion library for form validations
3 lines (2 loc) • 5.33 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("n4s")):"function"==typeof define&&define.amd?define(["n4s"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).n4s)}(this,(function(t){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function r(t){if(!("string"==typeof t||t instanceof String)){var r=e(t);throw null===t?r="null":"object"===r&&(r=t.constructor.name),new TypeError("Expected a string but received a ".concat(r))}}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;for(var r in e)void 0===t[r]&&(t[r]=e[r]);return t}var o={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_numeric_tld:!1,allow_wildcard:!1,ignore_max_length:!1};var i="(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])",l="(".concat(i,"[.]){3}").concat(i),c=new RegExp("^".concat(l,"$")),a="(?:[0-9a-fA-F]{1,4})",u=new RegExp("^("+"(?:".concat(a,":){7}(?:").concat(a,"|:)|")+"(?:".concat(a,":){6}(?:").concat(l,"|:").concat(a,"|:)|")+"(?:".concat(a,":){5}(?::").concat(l,"|(:").concat(a,"){1,2}|:)|")+"(?:".concat(a,":){4}(?:(:").concat(a,"){0,1}:").concat(l,"|(:").concat(a,"){1,3}|:)|")+"(?:".concat(a,":){3}(?:(:").concat(a,"){0,2}:").concat(l,"|(:").concat(a,"){1,4}|:)|")+"(?:".concat(a,":){2}(?:(:").concat(a,"){0,3}:").concat(l,"|(:").concat(a,"){1,5}|:)|")+"(?:".concat(a,":){1}(?:(:").concat(a,"){0,4}:").concat(l,"|(:").concat(a,"){1,6}|:)|")+"(?::((?::".concat(a,"){0,5}:").concat(l,"|(?::").concat(a,"){1,7}|:))")+")(%[0-9a-zA-Z-.:]{1,})?$");function f(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return r(t),(e=String(e))?"4"===e?c.test(t):"6"===e&&u.test(t):f(t,4)||f(t,6)}function s(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],n=!0,o=!1,i=void 0;try{for(var l,c=t[Symbol.iterator]();!(n=(l=c.next()).done)&&(r.push(l.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return r}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return _(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return _(t,e)}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var d={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,allow_fragments:!0,allow_query_components:!0,validate_length:!0},p=/^\[([^\]]+)\](?::([0-9]+))?$/;function h(t,e){for(var r=0;r<e.length;r++){var n=e[r];if(t===n||(o=n,"[object RegExp]"===Object.prototype.toString.call(o)&&n.test(t)))return!0}var o;return!1}t.enforce.extend({isURL:function(t,e){if(r(t),!t||/[\s<>]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((e=n(e,d)).validate_length&&t.length>=2083)return!1;if(!e.allow_fragments&&t.includes("#"))return!1;if(!e.allow_query_components&&(t.includes("?")||t.includes("&")))return!1;var i,l,c,a,u,_,g,y;if(g=t.split("#"),t=g.shift(),g=t.split("?"),t=g.shift(),(g=t.split("://")).length>1){if(i=g.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(i))return!1}else{if(e.require_protocol)return!1;if("//"===t.slice(0,2)){if(!e.allow_protocol_relative_urls)return!1;g[0]=t.slice(2)}}if(""===(t=g.join("://")))return!1;if(g=t.split("/"),""===(t=g.shift())&&!e.require_host)return!0;if((g=t.split("@")).length>1){if(e.disallow_auth)return!1;if(""===g[0])return!1;if((l=g.shift()).indexOf(":")>=0&&l.split(":").length>2)return!1;var v=s(l.split(":"),2),m=v[0],w=v[1];if(""===m&&""===w)return!1}_=null,y=null;var b=(a=g.join("@")).match(p);if(b?(c="",y=b[1],_=b[2]||null):(c=(g=a.split(":")).shift(),g.length&&(_=g.join(":"))),null!==_&&_.length>0){if(u=parseInt(_,10),!/^[0-9]+$/.test(_)||u<=0||u>65535)return!1}else if(e.require_port)return!1;return e.host_whitelist?h(c,e.host_whitelist):""===c&&!e.require_host||!!(f(c)||function(t,e){r(t),(e=n(e,o)).allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1)),!0===e.allow_wildcard&&0===t.indexOf("*.")&&(t=t.substring(2));var i=t.split("."),l=i[i.length-1];if(e.require_tld){if(i.length<2)return!1;if(!e.allow_numeric_tld&&!/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(l))return!1;if(/\s/.test(l))return!1}return!(!e.allow_numeric_tld&&/^\d+$/.test(l))&&i.every((function(t){return!(t.length>63&&!e.ignore_max_length||!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(t)||/[\uff01-\uff5e]/.test(t)||/^-|-$/.test(t)||!e.allow_underscores&&/_/.test(t))}))}(c,e)||y&&f(y,6))&&(c=c||y,!e.host_blacklist||!h(c,e.host_blacklist))}})}));
//# sourceMappingURL=isURL.production.js.map