UNPKG

ease-url

Version:

Wow, such a ease url parser

2 lines 4.16 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.EaseUrl=e():t.EaseUrl=e()}(window,(function(){return function(t){var e={};function r(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,o){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(o,n,function(e){return t[e]}.bind(null,n));return o},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var o;Object.defineProperty(e,"__esModule",{value:!0}),e.Query=e.EaseUrl=void 0,function(t){t[t.BEFORE=0]="BEFORE",t[t.AFTER=1]="AFTER"}(o||(o={}));var n=function(){function t(t){this.path="/",this.host="",this.hash="",this.scheme="https",this._port=void 0,this._hashPos=o.AFTER,this.query=new i,t&&this.parse(t)}return t.parse=function(e){return new t(e)},Object.defineProperty(t.prototype,"port",{get:function(){var t;return null!==(t=this._port)&&void 0!==t?t:this.defaultPorts[this.scheme]},set:function(t){this._port=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"origin",{get:function(){var t=this.defaultPorts[this.scheme]==this.port?void 0:this.port;return(this.scheme?this.scheme+"://":"")+this.host+(t?":"+t:"")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"url",{get:function(){var t=this._hashPos==o.BEFORE?this.hash:"",e=this._hashPos==o.AFTER?this.hash:"";return""+this.origin+this.path+t+(this.query.params.length?"?"+this.query.search:"")+e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"defaultPorts",{get:function(){return{http:80,https:443}},enumerable:!1,configurable:!0}),t.prototype.parse=function(t){var e,r;if("string"==typeof t){var n=t.split("?"),i=n[0].split("#");i.length>1&&(this._hashPos=o.BEFORE,this.hash="#"+i[1]),(i=i[0].match(/(([a-z]+):\/\/)?([0-9a-z\.\-]+)(:([0-9]{2,7}))?(\/.*)?(#.*?)?/i))&&(this.scheme=null!==(e=i[2])&&void 0!==e?e:"https",this.host=i[3],this.path=null!==(r=i[6])&&void 0!==r?r:"/",this._port=Number(i[5])||void 0),n.length>1&&((i=n[1].split("#")).length>1&&(this._hashPos=o.AFTER,this.hash="#"+i[1]),this.query.parse(i[0]))}else"object"==typeof t&&(this.host=t.host,this.path=t.path||"/",this.hash=t.hash||"",this.scheme=t.scheme||"https",this._port=t.port,this.query.parse(t.query))},t}();e.EaseUrl=n;var i=function(){function t(t){void 0===t&&(t=[]),this.params=[],this.parse(t)}return t.prototype.parse=function(t){var e=this;void 0===t&&(t=[]);var r=t.constructor;if(this.params.length=0,r==Object)for(var o in t)this.params.push({key:o,value:t[o]});else r==Array?t.forEach((function(t){e.params.push({key:t.key,value:t.value})})):r==String&&t.split("&").forEach((function(t){var r=t.match(/([0-9a-z\.\-\_\[\]]+)(=(.*))?/i);r&&e.params.push({key:r[1],value:r[3]||""})}))},Object.defineProperty(t.prototype,"dict",{get:function(){var t={};return this.params.forEach((function(e){null!=t[e.key]?"object"==typeof t[e.key]?t[e.key].push(e.value):t[e.key]=[t[e.key],e.value]:t[e.key]=e.value})),t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"search",{get:function(){var t=[];return this.params.forEach((function(e){t.push(e.key+"="+e.value)})),t.length?t.join("&"):""},enumerable:!1,configurable:!0}),t.prototype.add=function(t,e){this.params.push({key:t,value:e})},t.prototype.remove=function(t){for(var e in this.params)if(this.params[e].key==t){this.params.splice(Number(e),1);break}},t}();e.Query=i}])})); //# sourceMappingURL=EaseUrl.js.map