Build 589089stable
Module 567243
7,571 characters · in 514.d733764d42c2ab66.jsDependencies
Source Raw
function(e,t,n){"use strict";var r=n(89738);function i(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var a=/^([a-z0-9.+-]+:)/i,o=/:[0-9]*$/,s=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,l=["'"].concat(["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n"," "])),u=["%","/","?",";","#"].concat(l),c=["/","?","#"],d=/^[+a-z0-9A-Z_-]{0,63}$/,f=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,p={javascript:!0,"javascript:":!0},h={javascript:!0,"javascript:":!0},m={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},g=n(591560);function v(e,t,n){if(e&&"object"==typeof e&&e instanceof i)return e;var r=new i;return r.parse(e,t,n),r}i.prototype.parse=function(e,t,n){if("string"!=typeof e)throw TypeError("Parameter 'url' must be a string, not "+typeof e);var i=e.indexOf("?"),o=-1!==i&&i<e.indexOf("#")?"?":"#",v=e.split(o);v[0]=v[0].replace(/\\/g,"/");var y=e=v.join(o);if(y=y.trim(),!n&&1===e.split("#").length){var b=s.exec(y);if(b)return this.path=y,this.href=y,this.pathname=b[1],b[2]?(this.search=b[2],t?this.query=g.parse(this.search.substr(1)):this.query=this.search.substr(1)):t&&(this.search="",this.query={}),this}var _=a.exec(y);if(_){var w=(_=_[0]).toLowerCase();this.protocol=w,y=y.substr(_.length)}if(n||_||y.match(/^\/\/[^@/]+@[^@/]+/)){var x="//"===y.substr(0,2);x&&!(_&&h[_])&&(y=y.substr(2),this.slashes=!0)}if(!h[_]&&(x||_&&!m[_])){for(var E,S,k=-1,T=0;T<c.length;T++){var C=y.indexOf(c[T]);-1!==C&&(-1===k||C<k)&&(k=C)}-1!==(S=-1===k?y.lastIndexOf("@"):y.lastIndexOf("@",k))&&(E=y.slice(0,S),y=y.slice(S+1),this.auth=decodeURIComponent(E)),k=-1;for(var T=0;T<u.length;T++){var C=y.indexOf(u[T]);-1!==C&&(-1===k||C<k)&&(k=C)}-1===k&&(k=y.length),this.host=y.slice(0,k),y=y.slice(k),this.parseHost(),this.hostname=this.hostname||"";var P="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!P)for(var A=this.hostname.split(/\./),T=0,M=A.length;T<M;T++){var R=A[T];if(R&&!R.match(d)){for(var I="",L=0,O=R.length;L<O;L++)R.charCodeAt(L)>127?I+="x":I+=R[L];if(!I.match(d)){var D=A.slice(0,T),F=A.slice(T+1),N=R.match(f);N&&(D.push(N[1]),F.unshift(N[2])),F.length&&(y="/"+F.join(".")+y),this.hostname=D.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),P||(this.hostname=r.toASCII(this.hostname));var V=this.port?":"+this.port:"",j=this.hostname||"";this.host=j+V,this.href+=this.host,P&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==y[0]&&(y="/"+y))}if(!p[w])for(var T=0,M=l.length;T<M;T++){var B=l[T];if(-1!==y.indexOf(B)){var U=encodeURIComponent(B);U===B&&(U=escape(B)),y=y.split(B).join(U)}}var K=y.indexOf("#");-1!==K&&(this.hash=y.substr(K),y=y.slice(0,K));var $=y.indexOf("?");if(-1!==$?(this.search=y.substr($),this.query=y.substr($+1),t&&(this.query=g.parse(this.query)),y=y.slice(0,$)):t&&(this.search="",this.query={}),y&&(this.pathname=y),m[w]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var V=this.pathname||"",z=this.search||"";this.path=V+z}return this.href=this.format(),this},i.prototype.format=function(){var e=this.auth||"";e&&(e=(e=encodeURIComponent(e)).replace(/%3A/i,":")+"@");var t=this.protocol||"",n=this.pathname||"",r=this.hash||"",i=!1,a="";this.host?i=e+this.host:this.hostname&&(i=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&"object"==typeof this.query&&Object.keys(this.query).length&&(a=g.stringify(this.query,{arrayFormat:"repeat",addQueryPrefix:!1}));var o=this.search||a&&"?"+a||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||m[t])&&!1!==i?(i="//"+(i||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):i||(i=""),r&&"#"!==r.charAt(0)&&(r="#"+r),o&&"?"!==o.charAt(0)&&(o="?"+o),t+i+(n=n.replace(/[?#]/g,function(e){return encodeURIComponent(e)}))+(o=o.replace("#","%23"))+r},i.prototype.resolve=function(e){return this.resolveObject(v(e,!1,!0)).format()},i.prototype.resolveObject=function(e){if("string"==typeof e){var t=new i;t.parse(e,!1,!0),e=t}for(var n=new i,r=Object.keys(this),a=0;a<r.length;a++){var o=r[a];n[o]=this[o]}if(n.hash=e.hash,""===e.href)return n.href=n.format(),n;if(e.slashes&&!e.protocol){for(var s=Object.keys(e),l=0;l<s.length;l++){var u=s[l];"protocol"!==u&&(n[u]=e[u])}return m[n.protocol]&&n.hostname&&!n.pathname&&(n.pathname="/",n.path=n.pathname),n.href=n.format(),n}if(e.protocol&&e.protocol!==n.protocol){if(!m[e.protocol]){for(var c=Object.keys(e),d=0;d<c.length;d++){var f=c[d];n[f]=e[f]}return n.href=n.format(),n}if(n.protocol=e.protocol,e.host||h[e.protocol])n.pathname=e.pathname;else{for(var p=(e.pathname||"").split("/");p.length&&!(e.host=p.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==p[0]&&p.unshift(""),p.length<2&&p.unshift(""),n.pathname=p.join("/")}if(n.search=e.search,n.query=e.query,n.host=e.host||"",n.auth=e.auth,n.hostname=e.hostname||e.host,n.port=e.port,n.pathname||n.search){var g=n.pathname||"",v=n.search||"";n.path=g+v}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var y=n.pathname&&"/"===n.pathname.charAt(0),b=e.host||e.pathname&&"/"===e.pathname.charAt(0),_=b||y||n.host&&e.pathname,w=_,x=n.pathname&&n.pathname.split("/")||[],p=e.pathname&&e.pathname.split("/")||[],E=n.protocol&&!m[n.protocol];if(E&&(n.hostname="",n.port=null,n.host&&(""===x[0]?x[0]=n.host:x.unshift(n.host)),n.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===p[0]?p[0]=e.host:p.unshift(e.host)),e.host=null),_=_&&(""===p[0]||""===x[0])),b)n.host=e.host||""===e.host?e.host:n.host,n.hostname=e.hostname||""===e.hostname?e.hostname:n.hostname,n.search=e.search,n.query=e.query,x=p;else if(p.length)x||(x=[]),x.pop(),x=x.concat(p),n.search=e.search,n.query=e.query;else if(null!=e.search){if(E){n.host=x.shift(),n.hostname=n.host;var S=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@");S&&(n.auth=S.shift(),n.hostname=S.shift(),n.host=n.hostname)}return n.search=e.search,n.query=e.query,(null!==n.pathname||null!==n.search)&&(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n}if(!x.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var k=x.slice(-1)[0],T=(n.host||e.host||x.length>1)&&("."===k||".."===k)||""===k,C=0,P=x.length;P>=0;P--)"."===(k=x[P])?x.splice(P,1):".."===k?(x.splice(P,1),C++):C&&(x.splice(P,1),C--);if(!_&&!w)for(;C--;)x.unshift("..");_&&""!==x[0]&&(!x[0]||"/"!==x[0].charAt(0))&&x.unshift(""),T&&"/"!==x.join("/").substr(-1)&&x.push("");var A=""===x[0]||x[0]&&"/"===x[0].charAt(0);if(E){n.hostname=A?"":x.length?x.shift():"",n.host=n.hostname;var S=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@");S&&(n.auth=S.shift(),n.hostname=S.shift(),n.host=n.hostname)}return(_=_||n.host&&x.length)&&!A&&x.unshift(""),x.length>0?n.pathname=x.join("/"):(n.pathname=null,n.path=null),(null!==n.pathname||null!==n.search)&&(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},i.prototype.parseHost=function(){var e=this.host,t=o.exec(e);t&&(":"!==(t=t[0])&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)},t.parse=v,t.resolve=function(e,t){return v(e,!1,!0).resolve(t)},t.resolveObject=function(e,t){return e?v(e,!1,!0).resolveObject(t):t},t.format=function(e){return("string"==typeof e&&(e=v(e)),e instanceof i)?e.format():i.prototype.format.call(e)},t.Url=i}