@andrewcaires/fetch 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/fetch v1.0.5
2
+ * @andrewcaires/fetch v1.0.6
3
3
  * Plugin for fetch api
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- "use strict";var t=require("@andrewcaires/utils.js");function e(t,e,o,r){return new(o||(o=Promise))((function(n,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const o={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",511:"Network Authentication Required"};class r extends t.EventEmitter{constructor(t={}){super(),this._options=Object.assign({headers:{},timeout:5e3},t)}delete(t,o){return e(this,void 0,void 0,(function*(){return this.fetch({method:"delete",path:t,query:o})}))}get(t,o){return e(this,void 0,void 0,(function*(){return this.fetch({method:"get",path:t,query:o})}))}head(t,o){return e(this,void 0,void 0,(function*(){return this.fetch({method:"head",path:t,query:o})}))}options(t,o){return e(this,void 0,void 0,(function*(){return this.fetch({method:"options",path:t,query:o})}))}patch(t,o,r){return e(this,void 0,void 0,(function*(){return this.fetch({method:"patch",path:t,body:o,query:r})}))}post(t,o,r){return e(this,void 0,void 0,(function*(){return this.fetch({method:"post",path:t,body:o,query:r})}))}put(t,o,r){return e(this,void 0,void 0,(function*(){return this.fetch({method:"put",path:t,body:o,query:r})}))}request(t,o){return e(this,void 0,void 0,(function*(){return this.fetch({method:"request",path:t,query:o})}))}fetch(t){return e(this,void 0,void 0,(function*(){const e=this._request(t),o={};try{this.emit("before",e),o.raw=yield fetch(e.url,e),o.data=yield this._data(o.raw),o.raw.ok||(o.error=this._status(o.raw)),this.emit("complete",o)}catch(t){this.emit("error",t),o.error=t.message}return o}))}_body(e){const o=e instanceof Blob,r=e instanceof FormData,n=!(o||r||t.isString(e));return{json:n,parse:n?e?JSON.stringify(e):null:e}}_data(t){var e;const o=(null===(e=t.headers.get("Content-Type"))||void 0===e?void 0:e.toLowerCase())||"",r=o.indexOf("text/html")>=0,n=o.indexOf("application/json")>=0;return!o||r?t.text():n?t.json():t.blob()}_headers(t){return Object.assign(Object.assign({},this._options.headers),t)}_request({url:t,path:e,query:o,method:r,body:n,headers:i,timeout:s}){t=this._url(t,e,o),r=r.toUpperCase(),i=this._headers(i);const{json:a,parse:u}=this._body(n);a&&(i["Content-Type"]="application/json");return{url:t,method:r,body:u,headers:i,signal:this._signal(s)}}_signal(e){const o=new AbortController;return t.isUndefined(e)&&(e=this._options.timeout),e&&setTimeout((()=>o.abort()),e),o.signal}_status(t){return t.statusText||o[t.status]||"ERROR"}_url(e,o,r){const n=new URL(o||"",e||this._options.url);return r&&t.forEachKey(r,((t,e)=>n.searchParams.set(e,t))),n.toString()}}exports.Fetch=r,exports.FetchStatusText=o;
7
+ "use strict";var t=require("@andrewcaires/utils.js");function e(t,e,o,r){return new(o||(o=Promise))((function(n,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const o={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",511:"Network Authentication Required"};class r extends t.EventEmitter{constructor(t={}){super(),this._options=Object.assign({headers:{},timeout:5e3},t)}delete(t,o){return e(this,void 0,void 0,(function*(){return this.fetch({method:"delete",path:t,query:o})}))}get(t,o){return e(this,void 0,void 0,(function*(){return this.fetch({method:"get",path:t,query:o})}))}head(t,o){return e(this,void 0,void 0,(function*(){return this.fetch({method:"head",path:t,query:o})}))}options(t,o){return e(this,void 0,void 0,(function*(){return this.fetch({method:"options",path:t,query:o})}))}patch(t,o,r){return e(this,void 0,void 0,(function*(){return this.fetch({method:"patch",path:t,body:o,query:r})}))}post(t,o,r){return e(this,void 0,void 0,(function*(){return this.fetch({method:"post",path:t,body:o,query:r})}))}put(t,o,r){return e(this,void 0,void 0,(function*(){return this.fetch({method:"put",path:t,body:o,query:r})}))}request(t,o){return e(this,void 0,void 0,(function*(){return this.fetch({method:"request",path:t,query:o})}))}fetch(t){return e(this,void 0,void 0,(function*(){const e=this._request(t),o={};try{this.emit("before",e),o.raw=yield fetch(e.url,e),o.data=yield this._data(o.raw),o.raw.ok||(o.error=this._status(o.raw)),this.emit("complete",o)}catch(t){this.emit("error",t),o.error=t.message}return o}))}_body(e){const o=e instanceof Blob,r=e instanceof FormData,n=e instanceof URLSearchParams,i=!(o||r||n||t.isString(e));return{json:i,parse:i?e?JSON.stringify(e):null:e}}_data(t){const e=this._header(t,"Content-Type").toLowerCase(),o=e.indexOf("text/html")>=0,r=e.indexOf("text/plain")>=0,n=e.indexOf("application/json")>=0;return!e||o||r?t.text():n?t.json():t.blob()}_header(t,e){return t.headers.get(e)||""}_headers(t){return Object.assign(Object.assign({},this._options.headers),t)}_request({url:t,path:e,query:o,method:r,body:n,headers:i,timeout:s}){t=this._url(t,e,o),r=r.toUpperCase(),i=this._headers(i);const{json:a,parse:u}=this._body(n);a&&!i["Content-Type"]&&(i["Content-Type"]="application/json");return{url:t,method:r,body:u,headers:i,signal:this._signal(s)}}_signal(e){const o=new AbortController;return t.isUndefined(e)&&(e=this._options.timeout),e&&setTimeout((()=>o.abort()),e),o.signal}_status(t){return t.statusText||o[t.status]||"ERROR"}_url(e,o,r){const n=new URL(o||"",e||this._options.url);return r&&t.forEachKey(r,((t,e)=>n.searchParams.set(e,t))),n.toString()}}exports.Fetch=r,exports.FetchStatusText=o;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @andrewcaires/fetch v1.0.5
2
+ * @andrewcaires/fetch v1.0.6
3
3
  * Plugin for fetch api
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
@@ -63,6 +63,7 @@ declare class Fetch extends EventEmitter {
63
63
  fetch(params: FetchParams): Promise<FetchResponse>;
64
64
  private _body;
65
65
  private _data;
66
+ private _header;
66
67
  private _headers;
67
68
  private _request;
68
69
  private _signal;
package/dist/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/fetch v1.0.5
2
+ * @andrewcaires/fetch v1.0.6
3
3
  * Plugin for fetch api
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- import{EventEmitter as t,isString as e,isUndefined as o,forEachKey as r}from"@andrewcaires/utils.js";function n(t,e,o,r){return new(o||(o=Promise))((function(n,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const i={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",511:"Network Authentication Required"};class s extends t{constructor(t={}){super(),this._options=Object.assign({headers:{},timeout:5e3},t)}delete(t,e){return n(this,void 0,void 0,(function*(){return this.fetch({method:"delete",path:t,query:e})}))}get(t,e){return n(this,void 0,void 0,(function*(){return this.fetch({method:"get",path:t,query:e})}))}head(t,e){return n(this,void 0,void 0,(function*(){return this.fetch({method:"head",path:t,query:e})}))}options(t,e){return n(this,void 0,void 0,(function*(){return this.fetch({method:"options",path:t,query:e})}))}patch(t,e,o){return n(this,void 0,void 0,(function*(){return this.fetch({method:"patch",path:t,body:e,query:o})}))}post(t,e,o){return n(this,void 0,void 0,(function*(){return this.fetch({method:"post",path:t,body:e,query:o})}))}put(t,e,o){return n(this,void 0,void 0,(function*(){return this.fetch({method:"put",path:t,body:e,query:o})}))}request(t,e){return n(this,void 0,void 0,(function*(){return this.fetch({method:"request",path:t,query:e})}))}fetch(t){return n(this,void 0,void 0,(function*(){const e=this._request(t),o={};try{this.emit("before",e),o.raw=yield fetch(e.url,e),o.data=yield this._data(o.raw),o.raw.ok||(o.error=this._status(o.raw)),this.emit("complete",o)}catch(t){this.emit("error",t),o.error=t.message}return o}))}_body(t){const o=t instanceof Blob,r=t instanceof FormData,n=!(o||r||e(t));return{json:n,parse:n?t?JSON.stringify(t):null:t}}_data(t){var e;const o=(null===(e=t.headers.get("Content-Type"))||void 0===e?void 0:e.toLowerCase())||"",r=o.indexOf("text/html")>=0,n=o.indexOf("application/json")>=0;return!o||r?t.text():n?t.json():t.blob()}_headers(t){return Object.assign(Object.assign({},this._options.headers),t)}_request({url:t,path:e,query:o,method:r,body:n,headers:i,timeout:s}){t=this._url(t,e,o),r=r.toUpperCase(),i=this._headers(i);const{json:a,parse:u}=this._body(n);a&&(i["Content-Type"]="application/json");return{url:t,method:r,body:u,headers:i,signal:this._signal(s)}}_signal(t){const e=new AbortController;return o(t)&&(t=this._options.timeout),t&&setTimeout((()=>e.abort()),t),e.signal}_status(t){return t.statusText||i[t.status]||"ERROR"}_url(t,e,o){const n=new URL(e||"",t||this._options.url);return o&&r(o,((t,e)=>n.searchParams.set(e,t))),n.toString()}}export{s as Fetch,i as FetchStatusText};
7
+ import{EventEmitter as t,isString as e,isUndefined as o,forEachKey as r}from"@andrewcaires/utils.js";function n(t,e,o,r){return new(o||(o=Promise))((function(n,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const i={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",511:"Network Authentication Required"};class s extends t{constructor(t={}){super(),this._options=Object.assign({headers:{},timeout:5e3},t)}delete(t,e){return n(this,void 0,void 0,(function*(){return this.fetch({method:"delete",path:t,query:e})}))}get(t,e){return n(this,void 0,void 0,(function*(){return this.fetch({method:"get",path:t,query:e})}))}head(t,e){return n(this,void 0,void 0,(function*(){return this.fetch({method:"head",path:t,query:e})}))}options(t,e){return n(this,void 0,void 0,(function*(){return this.fetch({method:"options",path:t,query:e})}))}patch(t,e,o){return n(this,void 0,void 0,(function*(){return this.fetch({method:"patch",path:t,body:e,query:o})}))}post(t,e,o){return n(this,void 0,void 0,(function*(){return this.fetch({method:"post",path:t,body:e,query:o})}))}put(t,e,o){return n(this,void 0,void 0,(function*(){return this.fetch({method:"put",path:t,body:e,query:o})}))}request(t,e){return n(this,void 0,void 0,(function*(){return this.fetch({method:"request",path:t,query:e})}))}fetch(t){return n(this,void 0,void 0,(function*(){const e=this._request(t),o={};try{this.emit("before",e),o.raw=yield fetch(e.url,e),o.data=yield this._data(o.raw),o.raw.ok||(o.error=this._status(o.raw)),this.emit("complete",o)}catch(t){this.emit("error",t),o.error=t.message}return o}))}_body(t){const o=t instanceof Blob,r=t instanceof FormData,n=t instanceof URLSearchParams,i=!(o||r||n||e(t));return{json:i,parse:i?t?JSON.stringify(t):null:t}}_data(t){const e=this._header(t,"Content-Type").toLowerCase(),o=e.indexOf("text/html")>=0,r=e.indexOf("text/plain")>=0,n=e.indexOf("application/json")>=0;return!e||o||r?t.text():n?t.json():t.blob()}_header(t,e){return t.headers.get(e)||""}_headers(t){return Object.assign(Object.assign({},this._options.headers),t)}_request({url:t,path:e,query:o,method:r,body:n,headers:i,timeout:s}){t=this._url(t,e,o),r=r.toUpperCase(),i=this._headers(i);const{json:a,parse:u}=this._body(n);a&&!i["Content-Type"]&&(i["Content-Type"]="application/json");return{url:t,method:r,body:u,headers:i,signal:this._signal(s)}}_signal(t){const e=new AbortController;return o(t)&&(t=this._options.timeout),t&&setTimeout((()=>e.abort()),t),e.signal}_status(t){return t.statusText||i[t.status]||"ERROR"}_url(t,e,o){const n=new URL(e||"",t||this._options.url);return o&&r(o,((t,e)=>n.searchParams.set(e,t))),n.toString()}}export{s as Fetch,i as FetchStatusText};
package/dist/index.min.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/fetch v1.0.5
2
+ * @andrewcaires/fetch v1.0.6
3
3
  * Plugin for fetch api
4
4
  * (c) 2023 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- var Fetch=function(t,e){"use strict";function o(t,e,o,r){return new(o||(o=Promise))((function(n,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const r={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",511:"Network Authentication Required"};class n extends e.EventEmitter{constructor(t={}){super(),this._options=Object.assign({headers:{},timeout:5e3},t)}delete(t,e){return o(this,void 0,void 0,(function*(){return this.fetch({method:"delete",path:t,query:e})}))}get(t,e){return o(this,void 0,void 0,(function*(){return this.fetch({method:"get",path:t,query:e})}))}head(t,e){return o(this,void 0,void 0,(function*(){return this.fetch({method:"head",path:t,query:e})}))}options(t,e){return o(this,void 0,void 0,(function*(){return this.fetch({method:"options",path:t,query:e})}))}patch(t,e,r){return o(this,void 0,void 0,(function*(){return this.fetch({method:"patch",path:t,body:e,query:r})}))}post(t,e,r){return o(this,void 0,void 0,(function*(){return this.fetch({method:"post",path:t,body:e,query:r})}))}put(t,e,r){return o(this,void 0,void 0,(function*(){return this.fetch({method:"put",path:t,body:e,query:r})}))}request(t,e){return o(this,void 0,void 0,(function*(){return this.fetch({method:"request",path:t,query:e})}))}fetch(t){return o(this,void 0,void 0,(function*(){const e=this._request(t),o={};try{this.emit("before",e),o.raw=yield fetch(e.url,e),o.data=yield this._data(o.raw),o.raw.ok||(o.error=this._status(o.raw)),this.emit("complete",o)}catch(t){this.emit("error",t),o.error=t.message}return o}))}_body(t){const o=t instanceof Blob,r=t instanceof FormData,n=!(o||r||e.isString(t));return{json:n,parse:n?t?JSON.stringify(t):null:t}}_data(t){var e;const o=(null===(e=t.headers.get("Content-Type"))||void 0===e?void 0:e.toLowerCase())||"",r=o.indexOf("text/html")>=0,n=o.indexOf("application/json")>=0;return!o||r?t.text():n?t.json():t.blob()}_headers(t){return Object.assign(Object.assign({},this._options.headers),t)}_request({url:t,path:e,query:o,method:r,body:n,headers:i,timeout:s}){t=this._url(t,e,o),r=r.toUpperCase(),i=this._headers(i);const{json:a,parse:u}=this._body(n);a&&(i["Content-Type"]="application/json");return{url:t,method:r,body:u,headers:i,signal:this._signal(s)}}_signal(t){const o=new AbortController;return e.isUndefined(t)&&(t=this._options.timeout),t&&setTimeout((()=>o.abort()),t),o.signal}_status(t){return t.statusText||r[t.status]||"ERROR"}_url(t,o,r){const n=new URL(o||"",t||this._options.url);return r&&e.forEachKey(r,((t,e)=>n.searchParams.set(e,t))),n.toString()}}return t.Fetch=n,t.FetchStatusText=r,t}({},UtilsJS);
7
+ var Fetch=function(t,e){"use strict";function o(t,e,o,r){return new(o||(o=Promise))((function(n,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const r={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",511:"Network Authentication Required"};class n extends e.EventEmitter{constructor(t={}){super(),this._options=Object.assign({headers:{},timeout:5e3},t)}delete(t,e){return o(this,void 0,void 0,(function*(){return this.fetch({method:"delete",path:t,query:e})}))}get(t,e){return o(this,void 0,void 0,(function*(){return this.fetch({method:"get",path:t,query:e})}))}head(t,e){return o(this,void 0,void 0,(function*(){return this.fetch({method:"head",path:t,query:e})}))}options(t,e){return o(this,void 0,void 0,(function*(){return this.fetch({method:"options",path:t,query:e})}))}patch(t,e,r){return o(this,void 0,void 0,(function*(){return this.fetch({method:"patch",path:t,body:e,query:r})}))}post(t,e,r){return o(this,void 0,void 0,(function*(){return this.fetch({method:"post",path:t,body:e,query:r})}))}put(t,e,r){return o(this,void 0,void 0,(function*(){return this.fetch({method:"put",path:t,body:e,query:r})}))}request(t,e){return o(this,void 0,void 0,(function*(){return this.fetch({method:"request",path:t,query:e})}))}fetch(t){return o(this,void 0,void 0,(function*(){const e=this._request(t),o={};try{this.emit("before",e),o.raw=yield fetch(e.url,e),o.data=yield this._data(o.raw),o.raw.ok||(o.error=this._status(o.raw)),this.emit("complete",o)}catch(t){this.emit("error",t),o.error=t.message}return o}))}_body(t){const o=t instanceof Blob,r=t instanceof FormData,n=t instanceof URLSearchParams,i=!(o||r||n||e.isString(t));return{json:i,parse:i?t?JSON.stringify(t):null:t}}_data(t){const e=this._header(t,"Content-Type").toLowerCase(),o=e.indexOf("text/html")>=0,r=e.indexOf("text/plain")>=0,n=e.indexOf("application/json")>=0;return!e||o||r?t.text():n?t.json():t.blob()}_header(t,e){return t.headers.get(e)||""}_headers(t){return Object.assign(Object.assign({},this._options.headers),t)}_request({url:t,path:e,query:o,method:r,body:n,headers:i,timeout:s}){t=this._url(t,e,o),r=r.toUpperCase(),i=this._headers(i);const{json:a,parse:u}=this._body(n);a&&!i["Content-Type"]&&(i["Content-Type"]="application/json");return{url:t,method:r,body:u,headers:i,signal:this._signal(s)}}_signal(t){const o=new AbortController;return e.isUndefined(t)&&(t=this._options.timeout),t&&setTimeout((()=>o.abort()),t),o.signal}_status(t){return t.statusText||r[t.status]||"ERROR"}_url(t,o,r){const n=new URL(o||"",t||this._options.url);return r&&e.forEachKey(r,((t,e)=>n.searchParams.set(e,t))),n.toString()}}return t.Fetch=n,t.FetchStatusText=r,t}({},UtilsJS);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrewcaires/fetch",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Plugin for fetch api",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "unpkg": "./dist/index.min.js",
@@ -36,14 +36,14 @@
36
36
  },
37
37
  "homepage": "https://github.com/andrewcaires/npm#readme",
38
38
  "dependencies": {
39
- "@andrewcaires/utils.js": "^0.2.21"
39
+ "@andrewcaires/utils.js": "^0.2.22"
40
40
  },
41
41
  "devDependencies": {
42
- "@rollup/plugin-commonjs": "^25.0.4",
43
- "@rollup/plugin-terser": "^0.4.3",
44
- "@rollup/plugin-typescript": "^11.1.4",
45
- "rollup": "^3.29.4",
46
- "rollup-plugin-dts": "^6.0.2",
42
+ "@rollup/plugin-commonjs": "^25.0.7",
43
+ "@rollup/plugin-terser": "^0.4.4",
44
+ "@rollup/plugin-typescript": "^11.1.5",
45
+ "rollup": "^4.9.1",
46
+ "rollup-plugin-dts": "^6.1.0",
47
47
  "tslib": "^2.6.2"
48
48
  }
49
49
  }