kollapsminoriteten/wp-content/plugins/the-events-calendar/common/vendor/ky/ky.min.js

8 lines
7.3 KiB
JavaScript
Raw Normal View History

2023-09-26 10:09:00 +02:00
/**
* Bundled by jsDelivr using Rollup v2.60.2 and Terser v5.10.0.
* Original file: /npm/ky@0.29.0/distribution/index.js
*
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
*/
class t extends Error{constructor(t,e,s){const o=`${t.status||0===t.status?t.status:""} ${t.statusText||""}`.trim();super(`Request failed with ${o?`status code ${o}`:"an unknown error"}`),this.name="HTTPError",this.response=t,this.request=e,this.options=s}}class e extends Error{constructor(t){super("Request timed out"),this.name="TimeoutError",this.request=t}}const s=t=>null!==t&&"object"==typeof t,o=(...t)=>{for(const e of t)if((!s(e)||Array.isArray(e))&&void 0!==e)throw new TypeError("The `options` argument must be an object");return n({},...t)},r=(t={},e={})=>{const s=new globalThis.Headers(t),o=e instanceof globalThis.Headers,r=new globalThis.Headers(e);for(const[t,e]of r.entries())o&&"undefined"===e||void 0===e?s.delete(t):s.set(t,e);return s},n=(...t)=>{let e={},o={};for(const i of t)if(Array.isArray(i))Array.isArray(e)||(e=[]),e=[...e,...i];else if(s(i)){for(let[t,o]of Object.entries(i))s(o)&&t in e&&(o=n(e[t],o)),e={...e,[t]:o};s(i.headers)&&(o=r(o,i.headers),e.headers=o)}return e},i="function"==typeof globalThis.AbortController,a="function"==typeof globalThis.ReadableStream,h="function"==typeof globalThis.FormData,u=["get","post","put","patch","head","delete"],p={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},l=Symbol("stop"),c=t=>u.includes(t)?t.toUpperCase():t,f=[413,429,503],d={limit:2,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:f,maxRetryAfter:Number.POSITIVE_INFINITY},y=(t={})=>{if("number"==typeof t)return{...d,limit:t};if(t.methods&&!Array.isArray(t.methods))throw new Error("retry.methods must be an array");if(t.statusCodes&&!Array.isArray(t.statusCodes))throw new Error("retry.statusCodes must be an array");return{...d,...t,afterStatusCodes:f}};class _{constructor(t,e={}){var s,o;if(this._retryCount=0,this._input=t,this._options={credentials:this._input.credentials||"same-origin",...e,headers:r(this._input.headers,e.headers),hooks:n({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},e.hooks),method:c(null!==(s=e.method)&&void 0!==s?s:this._input.method),prefixUrl:String(e.prefixUrl||""),retry:y(e.retry),throwHttpErrors:!1!==e.throwHttpErrors,timeout:void 0===e.timeout?1e4:e.timeout,fetch:null!==(o=e.fetch)&&void 0!==o?o:globalThis.fetch.bind(globalThis)},"string"!=typeof this._input&&!(this._input instanceof URL||this._input instanceof globalThis.Request))throw new TypeError("`input` must be a string, URL, or Request");if(this._options.prefixUrl&&"string"==typeof this._input){if(this._input.startsWith("/"))throw new Error("`input` must not begin with a slash when using `prefixUrl`");this._options.prefixUrl.endsWith("/")||(this._options.prefixUrl+="/"),this._input=this._options.prefixUrl+this._input}if(i&&(this.abortController=new globalThis.AbortController,this._options.signal&&this._options.signal.addEventListener("abort",(()=>{this.abortController.abort()})),this._options.signal=this.abortController.signal),this.request=new globalThis.Request(this._input,this._options),this._options.searchParams){const t="?"+("string"==typeof this._options.searchParams?this._options.searchParams.replace(/^\?/,""):new URLSearchParams(this._options.searchParams).toString()),e=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,t);!(h&&this._options.body instanceof globalThis.FormData||this._options.body instanceof URLSearchParams)||this._options.headers&&this._options.headers["content-type"]||this.request.headers.delete("content-type"),this.request=new globalThis.Request(new globalThis.Request(e,this.request),this._options)}void 0!==this._options.json&&(this._options.body=JSON.stringify(this._options.json),this.request.headers.set("content-type","application/json"),this.request=new globalThis.Request(this.request,{body:this._options.body}))}static create(e,s){const o=new _(e,s),r=async()=>{if(o._options.timeout>2147483647)throw new RangeError("The `timeout` option cannot be greater than 2147483647");await Promise.resolve();let e=await o._fetch();for(const t of o._options.hooks.afterResponse){
/*! MIT License © Sindre Sorhus */const m=t=>{const e=(e,s)=>_.create(e,o(t,s));for(const s of u)e[s]=(e,r)=>_.create(e,o(t,r,{method:s}));return e.create=t=>m(o(t)),e.extend=e=>m(o(t,e)),e.stop=l,e},b=m();export{t as HTTPError,e as TimeoutError,b as default};