Orchard/src/Orchard.Web/Modules/Orchard.Azure.MediaServices/Scripts/lib/uri.min.js
Sipke Schoorstra 2ad324d4e2 Merge branch 'dev' into issue/homepage-alias
Conflicts:
	src/Orchard.Web/Modules/Orchard.ImportExport/Views/Admin/ImportResult.cshtml
	src/Orchard.Web/Modules/Orchard.Layouts/Orchard.Layouts.csproj
2015-08-04 16:25:35 +01:00

1 line
25 KiB
JavaScript

!function(t,e){"object"==typeof exports?module.exports=e(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"==typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],e):t.URI=e(t.punycode,t.IPv6,t.SecondLevelDomains,t)}(this,function(t,e,r,s){function n(t,e){return this instanceof n?(void 0===t&&(t="undefined"!=typeof location?location.href+"":""),this.href(t),void 0!==e?this.absoluteTo(e):this):new n(t,e)}function i(t){return t.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function a(t){return void 0===t?"Undefined":String(Object.prototype.toString.call(t)).slice(8,-1)}function o(t){return"Array"===a(t)}function h(t,e){var r,s;if(o(e)){for(r=0,s=e.length;s>r;r++)if(!h(t,e[r]))return!1;return!0}var n=a(e);for(r=0,s=t.length;s>r;r++)if("RegExp"===n){if("string"==typeof t[r]&&t[r].match(e))return!0}else if(t[r]===e)return!0;return!1}function u(t,e){if(!o(t)||!o(e)||t.length!==e.length)return!1;t.sort(),e.sort();for(var r=0,s=t.length;s>r;r++)if(t[r]!==e[r])return!1;return!0}function p(t){return escape(t)}function c(t){return encodeURIComponent(t).replace(/[!'()*]/g,p).replace(/\*/g,"%2A")}var l=s&&s.URI;n.version="1.12.1";var d=n.prototype,f=Object.prototype.hasOwnProperty;n._parts=function(){return{protocol:null,username:null,password:null,hostname:null,urn:null,port:null,path:null,query:null,fragment:null,duplicateQueryParameters:n.duplicateQueryParameters,escapeQuerySpace:n.escapeQuerySpace}},n.duplicateQueryParameters=!1,n.escapeQuerySpace=!0,n.protocol_expression=/^[a-z][a-z0-9.+-]*$/i,n.idn_expression=/[^a-z0-9\.-]/i,n.punycode_expression=/(xn--)/i,n.ip4_expression=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/,n.ip6_expression=/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,n.find_uri_expression=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/gi,n.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/},n.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},n.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,n.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src"},n.getDomAttribute=function(t){if(t&&t.nodeName){var e=t.nodeName.toLowerCase();return"input"===e&&"image"!==t.type?void 0:n.domAttributes[e]}},n.encode=c,n.decode=decodeURIComponent,n.iso8859=function(){n.encode=escape,n.decode=unescape},n.unicode=function(){n.encode=c,n.decode=decodeURIComponent},n.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}}},n.encodeQuery=function(t,e){var r=n.encode(t+"");return void 0===e&&(e=n.escapeQuerySpace),e?r.replace(/%20/g,"+"):r},n.decodeQuery=function(t,e){t+="",void 0===e&&(e=n.escapeQuerySpace);try{return n.decode(e?t.replace(/\+/g,"%20"):t)}catch(r){return t}},n.recodePath=function(t){t=(t+"").split("/");for(var e=0,r=t.length;r>e;e++)t[e]=n.encodePathSegment(n.decode(t[e]));return t.join("/")},n.decodePath=function(t){t=(t+"").split("/");for(var e=0,r=t.length;r>e;e++)t[e]=n.decodePathSegment(t[e]);return t.join("/")};var m,_={encode:"encode",decode:"decode"},g=function(t,e){return function(r){return n[e](r+"").replace(n.characters[t][e].expression,function(r){return n.characters[t][e].map[r]})}};for(m in _)n[m+"PathSegment"]=g("pathname",_[m]);n.encodeReserved=g("reserved","encode"),n.parse=function(t,e){var r;return e||(e={}),r=t.indexOf("#"),r>-1&&(e.fragment=t.substring(r+1)||null,t=t.substring(0,r)),r=t.indexOf("?"),r>-1&&(e.query=t.substring(r+1)||null,t=t.substring(0,r)),"//"===t.substring(0,2)?(e.protocol=null,t=t.substring(2),t=n.parseAuthority(t,e)):(r=t.indexOf(":"),r>-1&&(e.protocol=t.substring(0,r)||null,e.protocol&&!e.protocol.match(n.protocol_expression)?e.protocol=void 0:"file"===e.protocol?t=t.substring(r+3):"//"===t.substring(r+1,r+3)?(t=t.substring(r+3),t=n.parseAuthority(t,e)):(t=t.substring(r+1),e.urn=!0))),e.path=t,e},n.parseHost=function(t,e){var r,s=t.indexOf("/");return-1===s&&(s=t.length),"["===t.charAt(0)?(r=t.indexOf("]"),e.hostname=t.substring(1,r)||null,e.port=t.substring(r+2,s)||null):t.indexOf(":")!==t.lastIndexOf(":")?(e.hostname=t.substring(0,s)||null,e.port=null):(r=t.substring(0,s).split(":"),e.hostname=r[0]||null,e.port=r[1]||null),e.hostname&&"/"!==t.substring(s).charAt(0)&&(s++,t="/"+t),t.substring(s)||"/"},n.parseAuthority=function(t,e){return t=n.parseUserinfo(t,e),n.parseHost(t,e)},n.parseUserinfo=function(t,e){var r=t.indexOf("/"),s=r>-1?t.lastIndexOf("@",r):t.indexOf("@");return s>-1&&(-1===r||r>s)?(r=t.substring(0,s).split(":"),e.username=r[0]?n.decode(r[0]):null,r.shift(),e.password=r[0]?n.decode(r.join(":")):null,t=t.substring(s+1)):(e.username=null,e.password=null),t},n.parseQuery=function(t,e){if(!t)return{};if(t=t.replace(/&+/g,"&").replace(/^\?*&*|&+$/g,""),!t)return{};for(var r,s,i={},a=t.split("&"),o=a.length,h=0;o>h;h++)r=a[h].split("="),s=n.decodeQuery(r.shift(),e),r=r.length?n.decodeQuery(r.join("="),e):null,i[s]?("string"==typeof i[s]&&(i[s]=[i[s]]),i[s].push(r)):i[s]=r;return i},n.build=function(t){var e="";return t.protocol&&(e+=t.protocol+":"),t.urn||!e&&!t.hostname||(e+="//"),e+=n.buildAuthority(t)||"","string"==typeof t.path&&("/"!==t.path.charAt(0)&&"string"==typeof t.hostname&&(e+="/"),e+=t.path),"string"==typeof t.query&&t.query&&(e+="?"+t.query),"string"==typeof t.fragment&&t.fragment&&(e+="#"+t.fragment),e},n.buildHost=function(t){var e="";return t.hostname?(n.ip6_expression.test(t.hostname)?e=t.port?e+("["+t.hostname+"]:"+t.port):e+t.hostname:(e+=t.hostname,t.port&&(e+=":"+t.port)),e):""},n.buildAuthority=function(t){return n.buildUserinfo(t)+n.buildHost(t)},n.buildUserinfo=function(t){var e="";return t.username&&(e+=n.encode(t.username),t.password&&(e+=":"+n.encode(t.password)),e+="@"),e},n.buildQuery=function(t,e,r){var s,i,a,h,u="";for(i in t)if(f.call(t,i)&&i)if(o(t[i]))for(s={},a=0,h=t[i].length;h>a;a++)void 0!==t[i][a]&&void 0===s[t[i][a]+""]&&(u+="&"+n.buildQueryParameter(i,t[i][a],r),!0!==e&&(s[t[i][a]+""]=!0));else void 0!==t[i]&&(u+="&"+n.buildQueryParameter(i,t[i],r));return u.substring(1)},n.buildQueryParameter=function(t,e,r){return n.encodeQuery(t,r)+(null!==e?"="+n.encodeQuery(e,r):"")},n.addQuery=function(t,e,r){if("object"==typeof e)for(var s in e)f.call(e,s)&&n.addQuery(t,s,e[s]);else{if("string"!=typeof e)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");void 0===t[e]?t[e]=r:("string"==typeof t[e]&&(t[e]=[t[e]]),o(r)||(r=[r]),t[e]=t[e].concat(r))}},n.removeQuery=function(t,e,r){var s;if(o(e))for(r=0,s=e.length;s>r;r++)t[e[r]]=void 0;else if("object"==typeof e)for(s in e)f.call(e,s)&&n.removeQuery(t,s,e[s]);else{if("string"!=typeof e)throw new TypeError("URI.addQuery() accepts an object, string as the first parameter");if(void 0!==r){if(t[e]===r)t[e]=void 0;else if(o(t[e])){s=t[e];var i,a,h={};if(o(r))for(i=0,a=r.length;a>i;i++)h[r[i]]=!0;else h[r]=!0;for(i=0,a=s.length;a>i;i++)void 0!==h[s[i]]&&(s.splice(i,1),a--,i--);t[e]=s}}else t[e]=void 0}},n.hasQuery=function(t,e,r,s){if("object"==typeof e){for(var i in e)if(f.call(e,i)&&!n.hasQuery(t,i,e[i]))return!1;return!0}if("string"!=typeof e)throw new TypeError("URI.hasQuery() accepts an object, string as the name parameter");switch(a(r)){case"Undefined":return e in t;case"Boolean":return t=Boolean(o(t[e])?t[e].length:t[e]),r===t;case"Function":return!!r(t[e],e,t);case"Array":return o(t[e])?(s?h:u)(t[e],r):!1;case"RegExp":return o(t[e])?s?h(t[e],r):!1:Boolean(t[e]&&t[e].match(r));case"Number":r=String(r);case"String":return o(t[e])?s?h(t[e],r):!1:t[e]===r;default:throw new TypeError("URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter")}},n.commonPath=function(t,e){var r,s=Math.min(t.length,e.length);for(r=0;s>r;r++)if(t.charAt(r)!==e.charAt(r)){r--;break}return 1>r?t.charAt(0)===e.charAt(0)&&"/"===t.charAt(0)?"/":"":(("/"!==t.charAt(r)||"/"!==e.charAt(r))&&(r=t.substring(0,r).lastIndexOf("/")),t.substring(0,r+1))},n.withinString=function(t,e,r){r||(r={});var s=r.start||n.findUri.start,i=r.end||n.findUri.end,a=r.trim||n.findUri.trim,o=/[a-z0-9-]=["']?$/i;for(s.lastIndex=0;;){var h=s.exec(t);if(!h)break;if(h=h.index,r.ignoreHtml){var u=t.slice(Math.max(h-3,0),h);if(u&&o.test(u))continue}var u=h+t.slice(h).search(i),p=t.slice(h,u).replace(a,"");r.ignore&&r.ignore.test(p)||(u=h+p.length,p=e(p,h,u,t),t=t.slice(0,h)+p+t.slice(u),s.lastIndex=h+p.length)}return s.lastIndex=0,t},n.ensureValidHostname=function(e){if(e.match(n.invalid_hostname_characters)){if(!t)throw new TypeError("Hostname '"+e+"' contains characters other than [A-Z0-9.-] and Punycode.js is not available");if(t.toASCII(e).match(n.invalid_hostname_characters))throw new TypeError("Hostname '"+e+"' contains characters other than [A-Z0-9.-]")}},n.noConflict=function(t){return t?(t={URI:this.noConflict()},URITemplate&&"function"==typeof URITemplate.noConflict&&(t.URITemplate=URITemplate.noConflict()),e&&"function"==typeof e.noConflict&&(t.IPv6=e.noConflict()),SecondLevelDomains&&"function"==typeof SecondLevelDomains.noConflict&&(t.SecondLevelDomains=SecondLevelDomains.noConflict()),t):(s.URI===this&&(s.URI=l),this)},d.build=function(t){return!0===t?this._deferred_build=!0:(void 0===t||this._deferred_build)&&(this._string=n.build(this._parts),this._deferred_build=!1),this},d.clone=function(){return new n(this)},d.valueOf=d.toString=function(){return this.build(!1)._string},_={protocol:"protocol",username:"username",password:"password",hostname:"hostname",port:"port"},g=function(t){return function(e,r){return void 0===e?this._parts[t]||"":(this._parts[t]=e||null,this.build(!r),this)}};for(m in _)d[m]=g(_[m]);_={query:"?",fragment:"#"},g=function(t,e){return function(r,s){return void 0===r?this._parts[t]||"":(null!==r&&(r+="",r.charAt(0)===e&&(r=r.substring(1))),this._parts[t]=r,this.build(!s),this)}};for(m in _)d[m]=g(m,_[m]);_={search:["?","query"],hash:["#","fragment"]},g=function(t,e){return function(r,s){var n=this[t](r,s);return"string"==typeof n&&n.length?e+n:n}};for(m in _)d[m]=g(_[m][1],_[m][0]);d.pathname=function(t,e){if(void 0===t||!0===t){var r=this._parts.path||(this._parts.hostname?"/":"");return t?n.decodePath(r):r}return this._parts.path=t?n.recodePath(t):"/",this.build(!e),this},d.path=d.pathname,d.href=function(t,e){var r;if(void 0===t)return this.toString();this._string="",this._parts=n._parts();var s=t instanceof n,i="object"==typeof t&&(t.hostname||t.path||t.pathname);if(t.nodeName&&(i=n.getDomAttribute(t),t=t[i]||"",i=!1),!s&&i&&void 0!==t.pathname&&(t=t.toString()),"string"==typeof t)this._parts=n.parse(t,this._parts);else{if(!s&&!i)throw new TypeError("invalid input");for(r in s=s?t._parts:t)f.call(this._parts,r)&&(this._parts[r]=s[r])}return this.build(!e),this},d.is=function(t){var e=!1,s=!1,i=!1,a=!1,o=!1,h=!1,u=!1,p=!this._parts.urn;switch(this._parts.hostname&&(p=!1,s=n.ip4_expression.test(this._parts.hostname),i=n.ip6_expression.test(this._parts.hostname),e=s||i,o=(a=!e)&&r&&r.has(this._parts.hostname),h=a&&n.idn_expression.test(this._parts.hostname),u=a&&n.punycode_expression.test(this._parts.hostname)),t.toLowerCase()){case"relative":return p;case"absolute":return!p;case"domain":case"name":return a;case"sld":return o;case"ip":return e;case"ip4":case"ipv4":case"inet4":return s;case"ip6":case"ipv6":case"inet6":return i;case"idn":return h;case"url":return!this._parts.urn;case"urn":return!!this._parts.urn;case"punycode":return u}return null};var y=d.protocol,v=d.port,b=d.hostname;d.protocol=function(t,e){if(void 0!==t&&t&&(t=t.replace(/:(\/\/)?$/,""),!t.match(n.protocol_expression)))throw new TypeError("Protocol '"+t+"' contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return y.call(this,t,e)},d.scheme=d.protocol,d.port=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0!==t&&(0===t&&(t=null),t&&(t+="",":"===t.charAt(0)&&(t=t.substring(1)),t.match(/[^0-9]/))))throw new TypeError("Port '"+t+"' contains characters other than [0-9]");return v.call(this,t,e)},d.hostname=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0!==t){var r={};n.parseHost(t,r),t=r.hostname}return b.call(this,t,e)},d.host=function(t,e){return this._parts.urn?void 0===t?"":this:void 0===t?this._parts.hostname?n.buildHost(this._parts):"":(n.parseHost(t,this._parts),this.build(!e),this)},d.authority=function(t,e){return this._parts.urn?void 0===t?"":this:void 0===t?this._parts.hostname?n.buildAuthority(this._parts):"":(n.parseAuthority(t,this._parts),this.build(!e),this)},d.userinfo=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t){if(!this._parts.username)return"";var r=n.buildUserinfo(this._parts);return r.substring(0,r.length-1)}return"@"!==t[t.length-1]&&(t+="@"),n.parseUserinfo(t,this._parts),this.build(!e),this},d.resource=function(t,e){var r;return void 0===t?this.path()+this.search()+this.hash():(r=n.parse(t),this._parts.path=r.path,this._parts.query=r.query,this._parts.fragment=r.fragment,this.build(!e),this)},d.subdomain=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,r)||""}return r=this._parts.hostname.length-this.domain().length,r=this._parts.hostname.substring(0,r),r=RegExp("^"+i(r)),t&&"."!==t.charAt(t.length-1)&&(t+="."),t&&n.ensureValidHostname(t),this._parts.hostname=this._parts.hostname.replace(r,t),this.build(!e),this},d.domain=function(t,e){if(this._parts.urn)return void 0===t?"":this;if("boolean"==typeof t&&(e=t,t=void 0),void 0===t){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.match(/\./g);return r&&2>r.length?this._parts.hostname:(r=this._parts.hostname.length-this.tld(e).length-1,r=this._parts.hostname.lastIndexOf(".",r-1)+1,this._parts.hostname.substring(r)||"")}if(!t)throw new TypeError("cannot set domain empty");return n.ensureValidHostname(t),!this._parts.hostname||this.is("IP")?this._parts.hostname=t:(r=RegExp(i(this.domain())+"$"),this._parts.hostname=this._parts.hostname.replace(r,t)),this.build(!e),this},d.tld=function(t,e){if(this._parts.urn)return void 0===t?"":this;if("boolean"==typeof t&&(e=t,t=void 0),void 0===t){if(!this._parts.hostname||this.is("IP"))return"";var s=this._parts.hostname.lastIndexOf("."),s=this._parts.hostname.substring(s+1);return!0!==e&&r&&r.list[s.toLowerCase()]?r.get(this._parts.hostname)||s:s}if(!t)throw new TypeError("cannot set TLD empty");if(t.match(/[^a-zA-Z0-9-]/)){if(!r||!r.is(t))throw new TypeError("TLD '"+t+"' contains characters other than [A-Z0-9]");s=RegExp(i(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(s,t)}else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");s=RegExp(i(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(s,t)}return this.build(!e),this},d.directory=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t||!0===t){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var r=this._parts.path.length-this.filename().length-1,r=this._parts.path.substring(0,r)||(this._parts.hostname?"/":"");return t?n.decodePath(r):r}return r=this._parts.path.length-this.filename().length,r=this._parts.path.substring(0,r),r=RegExp("^"+i(r)),this.is("relative")||(t||(t="/"),"/"!==t.charAt(0)&&(t="/"+t)),t&&"/"!==t.charAt(t.length-1)&&(t+="/"),t=n.recodePath(t),this._parts.path=this._parts.path.replace(r,t),this.build(!e),this},d.filename=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t||!0===t){if(!this._parts.path||"/"===this._parts.path)return"";var r=this._parts.path.lastIndexOf("/"),r=this._parts.path.substring(r+1);return t?n.decodePathSegment(r):r}r=!1,"/"===t.charAt(0)&&(t=t.substring(1)),t.match(/\.?\//)&&(r=!0);var s=RegExp(i(this.filename())+"$");return t=n.recodePath(t),this._parts.path=this._parts.path.replace(s,t),r?this.normalizePath(e):this.build(!e),this},d.suffix=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t||!0===t){if(!this._parts.path||"/"===this._parts.path)return"";var r=this.filename(),s=r.lastIndexOf(".");return-1===s?"":(r=r.substring(s+1),r=/^[a-z0-9%]+$/i.test(r)?r:"",t?n.decodePathSegment(r):r)}if("."===t.charAt(0)&&(t=t.substring(1)),r=this.suffix())s=RegExp(t?i(r)+"$":i("."+r)+"$");else{if(!t)return this;this._parts.path+="."+n.recodePath(t)}return s&&(t=n.recodePath(t),this._parts.path=this._parts.path.replace(s,t)),this.build(!e),this},d.segment=function(t,e,r){var s=this._parts.urn?":":"/",n=this.path(),i="/"===n.substring(0,1),n=n.split(s);if(void 0!==t&&"number"!=typeof t&&(r=e,e=t,t=void 0),void 0!==t&&"number"!=typeof t)throw Error("Bad segment '"+t+"', must be 0-based integer");if(i&&n.shift(),0>t&&(t=Math.max(n.length+t,0)),void 0===e)return void 0===t?n:n[t];if(null===t||void 0===n[t])if(o(e)){n=[],t=0;for(var a=e.length;a>t;t++)(e[t].length||n.length&&n[n.length-1].length)&&(n.length&&!n[n.length-1].length&&n.pop(),n.push(e[t]))}else(e||"string"==typeof e)&&(""===n[n.length-1]?n[n.length-1]=e:n.push(e));else e||"string"==typeof e&&e.length?n[t]=e:n.splice(t,1);return i&&n.unshift(""),this.path(n.join(s),r)},d.segmentCoded=function(t,e,r){var s,i;if("number"!=typeof t&&(r=e,e=t,t=void 0),void 0===e){if(t=this.segment(t,e,r),o(t))for(s=0,i=t.length;i>s;s++)t[s]=n.decode(t[s]);else t=void 0!==t?n.decode(t):void 0;return t}if(o(e))for(s=0,i=e.length;i>s;s++)e[s]=n.decode(e[s]);else e="string"==typeof e?n.encode(e):e;return this.segment(t,e,r)};var Q=d.query;return d.query=function(t,e){if(!0===t)return n.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("function"==typeof t){var r=n.parseQuery(this._parts.query,this._parts.escapeQuerySpace),s=t.call(this,r);return this._parts.query=n.buildQuery(s||r,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!e),this}return void 0!==t&&"string"!=typeof t?(this._parts.query=n.buildQuery(t,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!e),this):Q.call(this,t,e)},d.setQuery=function(t,e,r){var s=n.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("object"==typeof t)for(var i in t)f.call(t,i)&&(s[i]=t[i]);else{if("string"!=typeof t)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");s[t]=void 0!==e?e:null}return this._parts.query=n.buildQuery(s,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof t&&(r=e),this.build(!r),this},d.addQuery=function(t,e,r){var s=n.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return n.addQuery(s,t,void 0===e?null:e),this._parts.query=n.buildQuery(s,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof t&&(r=e),this.build(!r),this},d.removeQuery=function(t,e,r){var s=n.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return n.removeQuery(s,t,e),this._parts.query=n.buildQuery(s,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof t&&(r=e),this.build(!r),this},d.hasQuery=function(t,e,r){var s=n.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return n.hasQuery(s,t,e,r)},d.setSearch=d.setQuery,d.addSearch=d.addQuery,d.removeSearch=d.removeQuery,d.hasSearch=d.hasQuery,d.normalize=function(){return this._parts.urn?this.normalizeProtocol(!1).normalizeQuery(!1).normalizeFragment(!1).build():this.normalizeProtocol(!1).normalizeHostname(!1).normalizePort(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build()},d.normalizeProtocol=function(t){return"string"==typeof this._parts.protocol&&(this._parts.protocol=this._parts.protocol.toLowerCase(),this.build(!t)),this},d.normalizeHostname=function(r){return this._parts.hostname&&(this.is("IDN")&&t?this._parts.hostname=t.toASCII(this._parts.hostname):this.is("IPv6")&&e&&(this._parts.hostname=e.best(this._parts.hostname)),this._parts.hostname=this._parts.hostname.toLowerCase(),this.build(!r)),this},d.normalizePort=function(t){return"string"==typeof this._parts.protocol&&this._parts.port===n.defaultPorts[this._parts.protocol]&&(this._parts.port=null,this.build(!t)),this},d.normalizePath=function(t){if(this._parts.urn||!this._parts.path||"/"===this._parts.path)return this;var e,r,s,i=this._parts.path,a="";for("/"!==i.charAt(0)&&(e=!0,i="/"+i),i=i.replace(/(\/(\.\/)+)|(\/\.$)/g,"/").replace(/\/{2,}/g,"/"),e&&(a=i.substring(1).match(/^(\.\.\/)+/)||"")&&(a=a[0]);r=i.indexOf("/.."),-1!==r;)0!==r?(s=i.substring(0,r).lastIndexOf("/"),-1===s&&(s=r),i=i.substring(0,s)+i.substring(r+3)):i=i.substring(3);return e&&this.is("relative")&&(i=a+i.substring(1)),i=n.recodePath(i),this._parts.path=i,this.build(!t),this},d.normalizePathname=d.normalizePath,d.normalizeQuery=function(t){return"string"==typeof this._parts.query&&(this._parts.query.length?this.query(n.parseQuery(this._parts.query,this._parts.escapeQuerySpace)):this._parts.query=null,this.build(!t)),this},d.normalizeFragment=function(t){return this._parts.fragment||(this._parts.fragment=null,this.build(!t)),this},d.normalizeSearch=d.normalizeQuery,d.normalizeHash=d.normalizeFragment,d.iso8859=function(){var t=n.encode,e=n.decode;return n.encode=escape,n.decode=decodeURIComponent,this.normalize(),n.encode=t,n.decode=e,this},d.unicode=function(){var t=n.encode,e=n.decode;return n.encode=c,n.decode=unescape,this.normalize(),n.encode=t,n.decode=e,this},d.readable=function(){var e=this.clone();e.username("").password("").normalize();var r="";if(e._parts.protocol&&(r+=e._parts.protocol+"://"),e._parts.hostname&&(e.is("punycode")&&t?(r+=t.toUnicode(e._parts.hostname),e._parts.port&&(r+=":"+e._parts.port)):r+=e.host()),e._parts.hostname&&e._parts.path&&"/"!==e._parts.path.charAt(0)&&(r+="/"),r+=e.path(!0),e._parts.query){for(var s="",i=0,a=e._parts.query.split("&"),o=a.length;o>i;i++){var h=(a[i]||"").split("="),s=s+("&"+n.decodeQuery(h[0],this._parts.escapeQuerySpace).replace(/&/g,"%26"));void 0!==h[1]&&(s+="="+n.decodeQuery(h[1],this._parts.escapeQuerySpace).replace(/&/g,"%26"))}r+="?"+s.substring(1)}return r+=n.decodeQuery(e.hash(),!0)},d.absoluteTo=function(t){var e,r,s=this.clone(),i=["protocol","username","password","hostname","port"];if(this._parts.urn)throw Error("URNs do not have any generally defined hierarchical components");if(t instanceof n||(t=new n(t)),s._parts.protocol||(s._parts.protocol=t._parts.protocol),this._parts.hostname)return s;for(e=0;r=i[e];e++)s._parts[r]=t._parts[r];return s._parts.path?".."===s._parts.path.substring(-2)&&(s._parts.path+="/"):(s._parts.path=t._parts.path,s._parts.query||(s._parts.query=t._parts.query)),"/"!==s.path().charAt(0)&&(t=t.directory(),s._parts.path=(t?t+"/":"")+s._parts.path,s.normalizePath()),s.build(),s},d.relativeTo=function(t){var e,r,s,i,a=this.clone().normalize();if(a._parts.urn)throw Error("URNs do not have any generally defined hierarchical components");if(t=new n(t).normalize(),e=a._parts,r=t._parts,s=a.path(),i=t.path(),"/"!==s.charAt(0))throw Error("URI is already relative");if("/"!==i.charAt(0))throw Error("Cannot calculate a URI relative to another relative URI");return e.protocol===r.protocol&&(e.protocol=null),e.username!==r.username||e.password!==r.password||null!==e.protocol||null!==e.username||null!==e.password||e.hostname!==r.hostname||e.port!==r.port?a.build():(e.hostname=null,e.port=null,s===i?(e.path="",a.build()):(t=n.commonPath(a.path(),t.path()))?(r=r.path.substring(t.length).replace(/[^\/]*$/,"").replace(/.*?\//g,"../"),e.path=r+e.path.substring(t.length),a.build()):a.build())},d.equals=function(t){var e=this.clone();t=new n(t);var r,s={},i={},a={};if(e.normalize(),t.normalize(),e.toString()===t.toString())return!0;if(s=e.query(),i=t.query(),e.query(""),t.query(""),e.toString()!==t.toString()||s.length!==i.length)return!1;s=n.parseQuery(s,this._parts.escapeQuerySpace),i=n.parseQuery(i,this._parts.escapeQuerySpace);for(r in s)if(f.call(s,r)){if(o(s[r])){if(!u(s[r],i[r]))return!1}else if(s[r]!==i[r])return!1;a[r]=!0}for(r in i)if(f.call(i,r)&&!a[r])return!1;return!0},d.duplicateQueryParameters=function(t){return this._parts.duplicateQueryParameters=!!t,this},d.escapeQuerySpace=function(t){return this._parts.escapeQuerySpace=!!t,this},n});