-
Notifications
You must be signed in to change notification settings - Fork 55
/
url-polyfill.min.js
1 lines (1 loc) · 3.82 KB
/
url-polyfill.min.js
1
var g=typeof global!=="undefined"?global:typeof window!=="undefined"?window:typeof self!=="undefined"?self:this;(function(e){var t=function(){try{return!!Symbol.iterator}catch(e){return false}};var n=t();var r=function(e){var t={next:function(){var t=e.shift();return{done:t===void 0,value:t}}};if(n){t[Symbol.iterator]=function(){return t}}return t};var i=function(){var t=function(e){Object.defineProperty(this,"_entries",{value:{}});if(typeof e==="string"){if(e!==""){e=e.replace(/^\?/,"");var n=e.split("&");var r;for(var i=0;i<n.length;i++){r=n[i].split("=");this.append(decodeURIComponent(r[0]),r.length>1?decodeURIComponent(r[1]):"")}}}else if(e instanceof t){var o=this;e.forEach(function(e,t){o.append(e,t)})}};var i=t.prototype;i.append=function(e,t){if(e in this._entries){this._entries[e].push(t.toString())}else{this._entries[e]=[t.toString()]}};i.delete=function(e){delete this._entries[e]};i.get=function(e){return e in this._entries?this._entries[e][0]:null};i.getAll=function(e){return e in this._entries?this._entries[e].slice(0):[]};i.has=function(e){return e in this._entries};i.set=function(e,t){this._entries[e]=[t.toString()]};i.forEach=function(e,t){var n;for(var r in this._entries){if(this._entries.hasOwnProperty(r)){n=this._entries[r];for(var i=0;i<n.length;i++){e.call(t,n[i],r,this)}}}};i.keys=function(){var e=[];this.forEach(function(t,n){e.push(n)});return r(e)};i.values=function(){var e=[];this.forEach(function(t){e.push(t)});return r(e)};i.entries=function(){var e=[];this.forEach(function(t,n){e.push([t,n])});return r(e)};if(n){i[Symbol.iterator]=i.entries}i.toString=function(){var e="";this.forEach(function(t,n){if(e.length>0)e+="&";e+=encodeURIComponent(n)+"="+encodeURIComponent(t)});return e};e.URLSearchParams=t};if(!("URLSearchParams"in e)){i()}})(g);(function(e){var t=function(){try{var e=new URL("b","http://a");e.pathname="c%20d";return e.href==="http://a/c%20d"&&e.searchParams}catch(e){return false}};var n=function(){var t=e.URL;var n=function(e,t){if(typeof e!=="string")throw new TypeError("Failed to construct 'URL': Invalid URL");var n=document.implementation.createHTMLDocument("");if(t){var r=n.createElement("base");r.href=t;n.head.appendChild(r)}var i=n.createElement("a");i.href=e;n.body.appendChild(i);if(i.protocol===":"||!/:/.test(i.href)){throw new TypeError("Invalid URL")}Object.defineProperty(this,"_anchorElement",{value:i})};var r=n.prototype;var i=function(e){Object.defineProperty(r,e,{get:function(){return this._anchorElement[e]},set:function(t){this._anchorElement[e]=t},enumerable:true})};["hash","host","hostname","href","port","protocol","search"].forEach(function(e){i(e)});Object.defineProperties(r,{toString:{get:function(){var e=this;return function(){return e.href}}},pathname:{get:function(){return this._anchorElement.pathname.replace(/(^\/?)/,"/")},set:function(e){this._anchorElement.pathname=e},enumerable:true},origin:{get:function(){return this._anchorElement.protocol+"//"+this._anchorElement.hostname+(this._anchorElement.port?":"+this._anchorElement.port:"")},enumerable:true},password:{get:function(){return""},set:function(e){},enumerable:true},username:{get:function(){return""},set:function(e){},enumerable:true},searchParams:{get:function(){var e=new URLSearchParams(this.search);var t=this;["append","delete","set"].forEach(function(n){var r=e[n];e[n]=function(){r.apply(e,arguments);t.search=e.toString()}});return e},enumerable:true}});n.createObjectURL=function(e){return t.createObjectURL.apply(t,arguments)};n.revokeObjectURL=function(e){return t.revokeObjectURL.apply(t,arguments)};e.URL=n};if(!t()){n()}if(e.location!==void 0&&!("origin"in e.location)){var r=function(){return e.location.protocol+"//"+e.location.hostname+(e.location.port?":"+e.location.port:"")};try{Object.defineProperty(e.location,"origin",{get:r,enumerable:true})}catch(t){setInterval(function(){e.location.origin=r()},100)}}})(g);