@andrewcaires/fetch 1.0.10 → 1.1.1
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 +3 -3
- package/dist/index.d.ts +22 -23
- package/dist/index.esm.js +3 -3
- package/dist/index.min.js +3 -3
- package/package.json +10 -9
package/dist/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/fetch v1.
|
|
2
|
+
* @andrewcaires/fetch v1.1.1
|
|
3
3
|
* Plugin for fetch api
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2025 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
"use strict";var t=require("@andrewcaires/utils.js");function e(t,e,n
|
|
7
|
+
"use strict";var t=require("@andrewcaires/utils.js");function e(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.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 t.EventEmitter{constructor(t){super(),this._options=Object.assign({headers:{},timeout:1e4},null!=t?t:{})}delete(t,r){return e(this,void 0,void 0,(function*(){return this.request({method:"delete",path:t,query:r})}))}static delete(t,r,o){return e(this,void 0,void 0,(function*(){return new n(o).delete(t,r)}))}get(t,r){return e(this,void 0,void 0,(function*(){return this.request({method:"get",path:t,query:r})}))}static get(t,r,o){return e(this,void 0,void 0,(function*(){return new n(o).get(t,r)}))}head(t,r){return e(this,void 0,void 0,(function*(){return this.request({method:"head",path:t,query:r})}))}static head(t,r,o){return e(this,void 0,void 0,(function*(){return new n(o).head(t,r)}))}options(t,r){return e(this,void 0,void 0,(function*(){return this.request({method:"options",path:t,query:r})}))}static options(t,r,o){return e(this,void 0,void 0,(function*(){return new n(o).options(t,r)}))}patch(t,r,n){return e(this,void 0,void 0,(function*(){return this.request({method:"patch",path:t,body:r,query:n})}))}static patch(t,r,o,i){return e(this,void 0,void 0,(function*(){return new n(i).patch(t,r,o)}))}post(t,r,n){return e(this,void 0,void 0,(function*(){return this.request({method:"post",path:t,body:r,query:n})}))}static post(t,r,o,i){return e(this,void 0,void 0,(function*(){return new n(i).post(t,r,o)}))}put(t,r,n){return e(this,void 0,void 0,(function*(){return this.request({method:"put",path:t,body:r,query:n})}))}static put(t,r,o,i){return e(this,void 0,void 0,(function*(){return new n(i).put(t,r,o)}))}request(t){return e(this,void 0,void 0,(function*(){const e=this._request(t),r={data:{}};try{this.emit("before",e),r.raw=yield fetch(e.url,e),r.data=yield this._data(r.raw),r.raw.ok||(r.error=this._status(r.raw)),this.emit("complete",r)}catch(t){this.emit("error",t),r.error=t.message}return r}))}static request(t,r){return e(this,void 0,void 0,(function*(){return new n(r).request(t)}))}_body(e){const r=e instanceof Blob,n=e instanceof FormData,o=e instanceof URLSearchParams,i=!(r||n||o||t.isString(e));return{json:i,parse:i?e?JSON.stringify(e):null:e}}_data(t){const e=this._header(t,"Content-Type").toLowerCase(),r=e.indexOf("text/html")>=0,n=e.indexOf("text/plain")>=0,o=e.indexOf("application/json")>=0;return!e||r||n?t.text():o?t.json():t.blob()}_header(t,e){var r;return null!==(r=t.headers.get(e))&&void 0!==r?r:""}_headers(t){return Object.assign(Object.assign({},this._options.headers),null!=t?t:{})}_request({url:t,path:e,query:r,method:n,body:o,headers:i,timeout:s}){t=this._url(t,e,r),n=n.toUpperCase(),i=this._headers(i);const{json:a,parse:u}=this._body(o);o&&a&&!i["Content-Type"]&&(i["Content-Type"]="application/json");return{url:t,method:n,body:u,headers:i,signal:this._signal(s)}}_signal(e){const r=new AbortController;return t.isUndefined(e)&&(e=this._options.timeout),e&&setTimeout((()=>r.abort()),e),r.signal}_status(t){var e;return t.statusText||(null!==(e=r[t.status])&&void 0!==e?e:"ERROR")}_url(e,r,n){const o=new URL(null!=r?r:"",null!=e?e:this._options.url);return n&&t.forEachKey(n,((t,e)=>o.searchParams.set(e,t))),o.toString()}}exports.Fetch=n,exports.FetchStatusText=r;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/fetch v1.
|
|
2
|
+
* @andrewcaires/fetch v1.1.1
|
|
3
3
|
* Plugin for fetch api
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2025 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
7
|
import { TypeObjectString, TypeNullable, EventEmitter } from '@andrewcaires/utils.js';
|
|
@@ -39,8 +39,8 @@ interface FetchRequest {
|
|
|
39
39
|
headers: FetchHeaders;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
interface FetchResponse {
|
|
43
|
-
data
|
|
42
|
+
interface FetchResponse<T = any> {
|
|
43
|
+
data: T;
|
|
44
44
|
error?: string;
|
|
45
45
|
raw?: Response;
|
|
46
46
|
}
|
|
@@ -48,24 +48,22 @@ interface FetchResponse {
|
|
|
48
48
|
declare class Fetch extends EventEmitter {
|
|
49
49
|
private _options;
|
|
50
50
|
constructor(options?: FetchOptions);
|
|
51
|
-
delete(path: string, query?: FetchQuery): Promise<FetchResponse
|
|
52
|
-
static delete(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse
|
|
53
|
-
get(path: string, query?: FetchQuery): Promise<FetchResponse
|
|
54
|
-
static get(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse
|
|
55
|
-
head(path: string, query?: FetchQuery): Promise<FetchResponse
|
|
56
|
-
static head(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse
|
|
57
|
-
options(path: string, query?: FetchQuery): Promise<FetchResponse
|
|
58
|
-
static options(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse
|
|
59
|
-
patch(path: string, body?: any, query?: FetchQuery): Promise<FetchResponse
|
|
60
|
-
static patch(path: string, body?: any, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse
|
|
61
|
-
post(path: string, body?: any, query?: FetchQuery): Promise<FetchResponse
|
|
62
|
-
static post(path: string, body?: any, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse
|
|
63
|
-
put(path: string, body?: any, query?: FetchQuery): Promise<FetchResponse
|
|
64
|
-
static put(path: string, body?: any, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse
|
|
65
|
-
request(
|
|
66
|
-
static request(
|
|
67
|
-
fetch(params: FetchParams): Promise<FetchResponse>;
|
|
68
|
-
static create(params: FetchParams, options?: FetchOptions): Promise<FetchResponse>;
|
|
51
|
+
delete<T = any>(path: string, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
52
|
+
static delete<T = any>(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
53
|
+
get<T = any>(path: string, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
54
|
+
static get<T = any>(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
55
|
+
head<T = any>(path: string, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
56
|
+
static head<T = any>(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
57
|
+
options<T = any>(path: string, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
58
|
+
static options<T = any>(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
59
|
+
patch<T = any>(path: string, body?: any, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
60
|
+
static patch<T = any>(path: string, body?: any, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
61
|
+
post<T = any>(path: string, body?: any, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
62
|
+
static post<T = any>(path: string, body?: any, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
63
|
+
put<T = any>(path: string, body?: any, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
64
|
+
static put<T = any>(path: string, body?: any, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
65
|
+
request<T = any>(params: FetchParams): Promise<FetchResponse<T>>;
|
|
66
|
+
static request<T = any>(params: FetchParams, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
69
67
|
private _body;
|
|
70
68
|
private _data;
|
|
71
69
|
private _header;
|
|
@@ -78,4 +76,5 @@ declare class Fetch extends EventEmitter {
|
|
|
78
76
|
|
|
79
77
|
declare const FetchStatusText: TypeObjectString;
|
|
80
78
|
|
|
81
|
-
export { Fetch,
|
|
79
|
+
export { Fetch, FetchStatusText };
|
|
80
|
+
export type { FetchBody, FetchHeaders, FetchOptions, FetchParams, FetchQuery, FetchRequest, FetchResponse };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/fetch v1.
|
|
2
|
+
* @andrewcaires/fetch v1.1.1
|
|
3
3
|
* Plugin for fetch api
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2025 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
import{EventEmitter as t,isString as e,isUndefined as n,forEachKey as
|
|
7
|
+
import{EventEmitter as t,isString as e,isUndefined as n,forEachKey as r}from"@andrewcaires/utils.js";function o(t,e,n,r){return new(n||(n=Promise))((function(o,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?o(t.value):(e=t.value,e instanceof n?e:new n((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:1e4},null!=t?t:{})}delete(t,e){return o(this,void 0,void 0,(function*(){return this.request({method:"delete",path:t,query:e})}))}static delete(t,e,n){return o(this,void 0,void 0,(function*(){return new s(n).delete(t,e)}))}get(t,e){return o(this,void 0,void 0,(function*(){return this.request({method:"get",path:t,query:e})}))}static get(t,e,n){return o(this,void 0,void 0,(function*(){return new s(n).get(t,e)}))}head(t,e){return o(this,void 0,void 0,(function*(){return this.request({method:"head",path:t,query:e})}))}static head(t,e,n){return o(this,void 0,void 0,(function*(){return new s(n).head(t,e)}))}options(t,e){return o(this,void 0,void 0,(function*(){return this.request({method:"options",path:t,query:e})}))}static options(t,e,n){return o(this,void 0,void 0,(function*(){return new s(n).options(t,e)}))}patch(t,e,n){return o(this,void 0,void 0,(function*(){return this.request({method:"patch",path:t,body:e,query:n})}))}static patch(t,e,n,r){return o(this,void 0,void 0,(function*(){return new s(r).patch(t,e,n)}))}post(t,e,n){return o(this,void 0,void 0,(function*(){return this.request({method:"post",path:t,body:e,query:n})}))}static post(t,e,n,r){return o(this,void 0,void 0,(function*(){return new s(r).post(t,e,n)}))}put(t,e,n){return o(this,void 0,void 0,(function*(){return this.request({method:"put",path:t,body:e,query:n})}))}static put(t,e,n,r){return o(this,void 0,void 0,(function*(){return new s(r).put(t,e,n)}))}request(t){return o(this,void 0,void 0,(function*(){const e=this._request(t),n={data:{}};try{this.emit("before",e),n.raw=yield fetch(e.url,e),n.data=yield this._data(n.raw),n.raw.ok||(n.error=this._status(n.raw)),this.emit("complete",n)}catch(t){this.emit("error",t),n.error=t.message}return n}))}static request(t,e){return o(this,void 0,void 0,(function*(){return new s(e).request(t)}))}_body(t){const n=t instanceof Blob,r=t instanceof FormData,o=t instanceof URLSearchParams,i=!(n||r||o||e(t));return{json:i,parse:i?t?JSON.stringify(t):null:t}}_data(t){const e=this._header(t,"Content-Type").toLowerCase(),n=e.indexOf("text/html")>=0,r=e.indexOf("text/plain")>=0,o=e.indexOf("application/json")>=0;return!e||n||r?t.text():o?t.json():t.blob()}_header(t,e){var n;return null!==(n=t.headers.get(e))&&void 0!==n?n:""}_headers(t){return Object.assign(Object.assign({},this._options.headers),null!=t?t:{})}_request({url:t,path:e,query:n,method:r,body:o,headers:i,timeout:s}){t=this._url(t,e,n),r=r.toUpperCase(),i=this._headers(i);const{json:a,parse:u}=this._body(o);o&&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 n(t)&&(t=this._options.timeout),t&&setTimeout((()=>e.abort()),t),e.signal}_status(t){var e;return t.statusText||(null!==(e=i[t.status])&&void 0!==e?e:"ERROR")}_url(t,e,n){const o=new URL(null!=e?e:"",null!=t?t:this._options.url);return n&&r(n,((t,e)=>o.searchParams.set(e,t))),o.toString()}}export{s as Fetch,i as FetchStatusText};
|
package/dist/index.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/fetch v1.
|
|
2
|
+
* @andrewcaires/fetch v1.1.1
|
|
3
3
|
* Plugin for fetch api
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2025 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
var Fetch=function(t,e){"use strict";function n(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{a(r.next(t))}catch(t){i(t)}}function u(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((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 o extends e.EventEmitter{constructor(t){super(),this._options=Object.assign({headers:{},timeout:1e4},null!=t?t:{})}delete(t,e){return n(this,void 0,void 0,(function*(){return this.
|
|
7
|
+
var Fetch=function(t,e){"use strict";function n(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{a(r.next(t))}catch(t){i(t)}}function u(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}a((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 o extends e.EventEmitter{constructor(t){super(),this._options=Object.assign({headers:{},timeout:1e4},null!=t?t:{})}delete(t,e){return n(this,void 0,void 0,(function*(){return this.request({method:"delete",path:t,query:e})}))}static delete(t,e,r){return n(this,void 0,void 0,(function*(){return new o(r).delete(t,e)}))}get(t,e){return n(this,void 0,void 0,(function*(){return this.request({method:"get",path:t,query:e})}))}static get(t,e,r){return n(this,void 0,void 0,(function*(){return new o(r).get(t,e)}))}head(t,e){return n(this,void 0,void 0,(function*(){return this.request({method:"head",path:t,query:e})}))}static head(t,e,r){return n(this,void 0,void 0,(function*(){return new o(r).head(t,e)}))}options(t,e){return n(this,void 0,void 0,(function*(){return this.request({method:"options",path:t,query:e})}))}static options(t,e,r){return n(this,void 0,void 0,(function*(){return new o(r).options(t,e)}))}patch(t,e,r){return n(this,void 0,void 0,(function*(){return this.request({method:"patch",path:t,body:e,query:r})}))}static patch(t,e,r,i){return n(this,void 0,void 0,(function*(){return new o(i).patch(t,e,r)}))}post(t,e,r){return n(this,void 0,void 0,(function*(){return this.request({method:"post",path:t,body:e,query:r})}))}static post(t,e,r,i){return n(this,void 0,void 0,(function*(){return new o(i).post(t,e,r)}))}put(t,e,r){return n(this,void 0,void 0,(function*(){return this.request({method:"put",path:t,body:e,query:r})}))}static put(t,e,r,i){return n(this,void 0,void 0,(function*(){return new o(i).put(t,e,r)}))}request(t){return n(this,void 0,void 0,(function*(){const e=this._request(t),n={data:{}};try{this.emit("before",e),n.raw=yield fetch(e.url,e),n.data=yield this._data(n.raw),n.raw.ok||(n.error=this._status(n.raw)),this.emit("complete",n)}catch(t){this.emit("error",t),n.error=t.message}return n}))}static request(t,e){return n(this,void 0,void 0,(function*(){return new o(e).request(t)}))}_body(t){const n=t instanceof Blob,r=t instanceof FormData,o=t instanceof URLSearchParams,i=!(n||r||o||e.isString(t));return{json:i,parse:i?t?JSON.stringify(t):null:t}}_data(t){const e=this._header(t,"Content-Type").toLowerCase(),n=e.indexOf("text/html")>=0,r=e.indexOf("text/plain")>=0,o=e.indexOf("application/json")>=0;return!e||n||r?t.text():o?t.json():t.blob()}_header(t,e){var n;return null!==(n=t.headers.get(e))&&void 0!==n?n:""}_headers(t){return Object.assign(Object.assign({},this._options.headers),null!=t?t:{})}_request({url:t,path:e,query:n,method:r,body:o,headers:i,timeout:s}){t=this._url(t,e,n),r=r.toUpperCase(),i=this._headers(i);const{json:u,parse:a}=this._body(o);o&&u&&!i["Content-Type"]&&(i["Content-Type"]="application/json");return{url:t,method:r,body:a,headers:i,signal:this._signal(s)}}_signal(t){const n=new AbortController;return e.isUndefined(t)&&(t=this._options.timeout),t&&setTimeout((()=>n.abort()),t),n.signal}_status(t){var e;return t.statusText||(null!==(e=r[t.status])&&void 0!==e?e:"ERROR")}_url(t,n,r){const o=new URL(null!=n?n:"",null!=t?t:this._options.url);return r&&e.forEachKey(r,((t,e)=>o.searchParams.set(e,t))),o.toString()}}return t.Fetch=o,t.FetchStatusText=r,t}({},UtilsJS);
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrewcaires/fetch",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Plugin for fetch api",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "./dist/index.cjs.js",
|
|
6
7
|
"unpkg": "./dist/index.min.js",
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
@@ -36,16 +37,16 @@
|
|
|
36
37
|
},
|
|
37
38
|
"homepage": "https://github.com/andrewcaires/npm#readme",
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@andrewcaires/utils.js": "^0.
|
|
40
|
+
"@andrewcaires/utils.js": "^0.4.14"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@rollup/plugin-commonjs": "^
|
|
43
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
43
44
|
"@rollup/plugin-terser": "^0.4.4",
|
|
44
|
-
"@rollup/plugin-typescript": "^
|
|
45
|
-
"eslint": "^9.
|
|
46
|
-
"rollup": "^4.
|
|
47
|
-
"rollup-plugin-dts": "^6.
|
|
48
|
-
"tslib": "^2.
|
|
49
|
-
"typescript-eslint": "^8.
|
|
45
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
46
|
+
"eslint": "^9.34.0",
|
|
47
|
+
"rollup": "^4.50.0",
|
|
48
|
+
"rollup-plugin-dts": "^6.2.3",
|
|
49
|
+
"tslib": "^2.8.1",
|
|
50
|
+
"typescript-eslint": "^8.42.0"
|
|
50
51
|
}
|
|
51
52
|
}
|