UNPKG

n4s

Version:

Assertion library for form validations

3 lines (2 loc) 5.12 kB
import{enforce as t}from"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 n(t){if(!("string"==typeof t||t instanceof String)){var n=r(t);throw null===t?n="null":"object"===n&&(n=t.constructor.name),new TypeError("Expected a string but received a ".concat(n))}}function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;for(var n in r)void 0===t[n]&&(t[n]=r[n]);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 r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return n(t),(r=String(r))?"4"===r?c.test(t):"6"===r&&u.test(t):f(t,4)||f(t,6)}function s(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 n=[],e=!0,o=!1,i=void 0;try{for(var l,c=t[Symbol.iterator]();!(e=(l=c.next()).done)&&(n.push(l.value),!r||n.length!==r);e=!0);}catch(t){o=!0,i=t}finally{try{e||null==c.return||c.return()}finally{if(o)throw i}}return n}(t,r)||function(t,r){if(!t)return;if("string"==typeof t)return _(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))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 n=0,e=new Array(r);n<r;n++)e[n]=t[n];return e}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 n=0;n<r.length;n++){var e=r[n];if(t===e||(o=e,"[object RegExp]"===Object.prototype.toString.call(o)&&e.test(t)))return!0}var o;return!1}t.extend({isURL:function(t,r){if(n(t),!t||/[\s<>]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;if((r=e(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=s(l.split(":"),2),m=v[0],w=v[1];if(""===m&&""===w)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||!!(f(c)||function(t,r){n(t),(r=e(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&&f(y,6))&&(c=c||y,!r.host_blacklist||!d(c,r.host_blacklist))}}); //# sourceMappingURL=isURL.production.js.map