UNPKG

n4s

Version:

Assertion library for form validations

3 lines (2 loc) 5.13 kB
"use strict";var t=require("n4s");function r(t){return r="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},r(t)}function e(t){if(!("string"==typeof t||t instanceof String)){var e=r(t);throw null===t?e="null":"object"===e&&(e=t.constructor.name),new TypeError("Expected a string but received a ".concat(e))}}function n(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;for(var e in r)void 0===t[e]&&(t[e]=r[e]);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 s(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return e(t),(r=String(r))?"4"===r?c.test(t):"6"===r&&u.test(t):s(t,4)||s(t,6)}function f(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var e=[],n=!0,o=!1,i=void 0;try{for(var l,c=t[Symbol.iterator]();!(n=(l=c.next()).done)&&(e.push(l.value),!r||e.length!==r);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==c.return||c.return()}finally{if(o)throw i}}return e}(t,r)||function(t,r){if(!t)return;if("string"==typeof t)return _(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return _(t,r)}(t,r)||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,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var p={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},h=/^\[([^\]]+)\](?::([0-9]+))?$/;function d(t,r){for(var e=0;e<r.length;e++){var n=r[e];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,r){if(e(t),!t||/[\s<>]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((r=n(r,p)).validate_length&&t.length>=2083)return!1;if(!r.allow_fragments&&t.includes("#"))return!1;if(!r.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(),r.require_valid_protocol&&-1===r.protocols.indexOf(i))return!1}else{if(r.require_protocol)return!1;if("//"===t.slice(0,2)){if(!r.allow_protocol_relative_urls)return!1;g[0]=t.slice(2)}}if(""===(t=g.join("://")))return!1;if(g=t.split("/"),""===(t=g.shift())&&!r.require_host)return!0;if((g=t.split("@")).length>1){if(r.disallow_auth)return!1;if(""===g[0])return!1;if((l=g.shift()).indexOf(":")>=0&&l.split(":").length>2)return!1;var v=f(l.split(":"),2),w=v[0],m=v[1];if(""===w&&""===m)return!1}_=null,y=null;var b=(a=g.join("@")).match(h);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(r.require_port)return!1;return r.host_whitelist?d(c,r.host_whitelist):""===c&&!r.require_host||!!(s(c)||function(t,r){e(t),(r=n(r,o)).allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1)),!0===r.allow_wildcard&&0===t.indexOf("*.")&&(t=t.substring(2));var i=t.split("."),l=i[i.length-1];if(r.require_tld){if(i.length<2)return!1;if(!r.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!(!r.allow_numeric_tld&&/^\d+$/.test(l))&&i.every((function(t){return!(t.length>63&&!r.ignore_max_length||!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(t)||/[\uff01-\uff5e]/.test(t)||/^-|-$/.test(t)||!r.allow_underscores&&/_/.test(t))}))}(c,r)||y&&s(y,6))&&(c=c||y,!r.host_blacklist||!d(c,r.host_blacklist))}}); //# sourceMappingURL=isURL.production.js.map