-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuri.min.js
2 lines (2 loc) · 2.93 KB
/
uri.min.js
1
2
/*! lil-uri - v0.3.1 - MIT License - https://github.com/lil-js/uri */
(function(t,r){if(typeof define==="function"&&define.amd){define(["exports"],r)}else if(typeof exports==="object"){r(exports);if(typeof module==="object"&&module!==null){module.exports=exports=exports.uri}}else{r(t.lil=t.lil||{})}})(this,(function(t){"use strict";var r="0.2.2";var e=/^(?:([^:\/?#]+):\/\/)?((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?)?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i;function o(t){return typeof t==="string"}function s(t){try{return decodeURIComponent(t)}catch(r){return unescape(t)}}function n(t){var r={};if(typeof t==="string"){t.split("&").forEach((function(t){t=t.split("=");if(r.hasOwnProperty(t[0])){r[t[0]]=Array.isArray(r[t[0]])?r[t[0]]:[r[t[0]]];r[t[0]].push(t[1])}else{r[t[0]]=t[1]}}));return r}}function u(t){return function(r){if(r){this.parts[t]=o(r)?s(r):r;return this}this.parts=this.parse(this.build());return this.parts[t]}}function i(t){this.uri=t||null;if(o(t)&&t.length){this.parts=this.parse(t)}else{this.parts={}}}i.prototype.parse=function(t){var r=s(t||"").match(e);var o=(r[3]||"").split(":");var u=o.length?(r[2]||"").replace(/(.*\@)/,""):r[2];return{uri:r[0],protocol:r[1],host:u,hostname:r[4],port:r[5],auth:r[3],user:o[0],password:o[1],path:r[6],search:r[7],query:n(r[7]),hash:r[8]}};i.prototype.protocol=function(t){return u("protocol").call(this,t)};i.prototype.host=function(t){return u("host").call(this,t)};i.prototype.hostname=function(t){return u("hostname").call(this,t)};i.prototype.port=function(t){return u("port").call(this,t)};i.prototype.auth=function(t){return u("host").call(this,t)};i.prototype.user=function(t){return u("user").call(this,t)};i.prototype.password=function(t){return u("password").call(this,t)};i.prototype.path=function(t){return u("path").call(this,t)};i.prototype.search=function(t){return u("search").call(this,t)};i.prototype.query=function(t){return t&&typeof t==="object"?u("query").call(this,t):this.parts.query};i.prototype.hash=function(t){return u("hash").call(this,t)};i.prototype.get=function(t){return this.parts[t]||""};i.prototype.build=i.prototype.toString=i.prototype.valueOf=function(){var t=this.parts,r=[];if(t.protocol)r.push(t.protocol+"://");if(t.auth)r.push(t.auth+"@");else if(t.user)r.push(t.user+(t.password?":"+t.password:"")+"@");if(t.host){r.push(t.host)}else{if(t.hostname)r.push(t.hostname);if(t.port)r.push(":"+t.port)}if(t.path)r.push(t.path);if(t.query&&typeof t.query==="object"){if(!t.path)r.push("/");r.push("?"+Object.keys(t.query).map((function(r){if(Array.isArray(t.query[r])){return t.query[r].map((function(t){return r+(t?"="+t:"")})).join("&")}else{return r+(t.query[r]!=null?"="+t.query[r]:"")}})).join("&"))}else if(t.search){r.push("?"+t.search)}if(t.hash){if(!t.path)r.push("/");r.push("#"+t.hash)}return this.url=r.filter((function(t){return o(t)})).join("")};function p(t){return new i(t)}function h(t){return typeof t==="string"&&e.test(t)}p.VERSION=r;p.is=p.isURL=h;p.URI=i;return t.uri=p}));