1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-14 22:10:18 +00:00
musix-oss/node_modules/snekfetch/browser.js

1 line
4.4 KiB
JavaScript
Raw Normal View History

2019-05-30 09:06:47 +00:00
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Snekfetch=e():t.Snekfetch=e()}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function s(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,s),r.l=!0,r.exports}return s.m=t,s.c=e,s.d=function(t,e,n){s.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=0)}([function(t,e,s){t.exports=s(1)},function(t,e,s){const n="undefined"!=typeof window,r=s(2),o=s(n?3:4);class i extends o.Extension{constructor(t,e,s={}){super(),this.options=Object.assign({version:1,qs:r,followRedirects:!0},s),this.request=o.buildRequest.call(this,t,e,s),s.headers&&this.set(s.headers),s.query&&this.query(s.query),s.data&&this.send(s.data)}query(t,e){if(this.request.query||(this.request.query={}),null!==t&&"object"==typeof t)for(const[e,s]of Object.entries(t))this.query(e,s);else this.request.query[t]=e;return this}set(t,e){if(null!==t&&"object"==typeof t)for(const e of Object.keys(t))this.set(e,t[e]);else this.request.setHeader(t,e);return this}attach(...t){const e=this.data instanceof o.FormData?this.data:this.data=new o.FormData;if("object"==typeof t[0])for(const[e,s]of Object.entries(t[0]))this.attach(e,s);else e.append(...t);return this}send(t){if(t instanceof o.FormData||o.shouldSendRaw(t))this.data=t;else if(null!==t&&"object"==typeof t){const e=this.request.getHeader("content-type");let s;e?e.includes("json")?s=JSON.stringify:e.includes("urlencoded")&&(s=this.options.qs.stringify):(this.set("Content-Type","application/json"),s=JSON.stringify),this.data=s(t)}else this.data=t;return this}then(t,e){return this._response?this._response.then(t,e):this._response=o.finalizeRequest.call(this).then(({response:t,raw:e,redirect:s,headers:n})=>{if(s){let e=this.request.method;[301,302].includes(t.statusCode)?("HEAD"!==e&&(e="GET"),this.data=null):303===t.statusCode&&(e="GET");const n=this.request.getHeaders();return delete n.host,new i(e,s,{data:this.data,headers:n,version:this.options.version})}const r=t.statusCode||t.status,a=this,u={request:this.request,get body(){delete u.body;const t=this.headers["content-type"];if(t&&t.includes("application/json"))try{u.body=JSON.parse(u.text)}catch(t){u.body=u.text}else t&&t.includes("application/x-www-form-urlencoded")?u.body=a.options.qs.parse(u.text):u.body=e;return u.body},text:e.toString(),ok:r>=200&&r<400,headers:n||t.headers,status:r,statusText:t.statusText||o.STATUS_CODES[t.statusCode]};if(u.ok)return u;{const t=new Error(`${u.status} ${u.statusText}`.trim());return Object.assign(t,u),Promise.reject(t)}}).then(t,e)}catch(t){return this.then(null,t)}end(t){return this.then(e=>t?t(null,e):e,e=>t?t(e,e.status?e:null):Promise.reject(e))}_finalizeRequest(){if(this.request&&("HEAD"!==this.request.method&&this.set("Accept-Encoding","gzip, deflate"),this.data&&this.data.getBoundary&&this.set("Content-Type",`multipart/form-data; boundary=${this.data.getBoundary()}`),this.request.query)){const[t,e]=this.request.path.split("?");this.request.path=`${t}?${this.options.qs.stringify(this.request.query)}${e?`&${e}`:""}`}}}i.METHODS=o.METHODS.concat("BREW").filter(t=>"M-SEARCH"!==t);for(const t of i.METHODS)i[t.toLowerCase()]=function(e,s){return new(this.prototype instanceof i?this:i)(t,e,s)};t.exports=i},function(t,e){({parse:t=>{const e={};for(const[s,n]of new Window.URLSearchParams(t).entries())e[s]=n;return e},stringify:t=>new window.URLSearchParams(t).toString()})},function(t,e){t.exports={buildRequest:function(t,e){return{method:t,path:e,redirect:this.options.followRedirects?"follow":"manual",headers:{},setHeader(t,e){this.headers[t.toLowerCase()]=e},getHeader(t){return this.headers[t.toLowerCase()]}}},finalizeRequest:function(){return this._finalizeRequest(),this.da