@andrewcaires/fetch 1.1.0 → 1.2.0
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/LICENSE +1 -1
- package/dist/index.cjs.js +3 -3
- package/dist/index.d.ts +32 -25
- package/dist/index.esm.js +3 -3
- package/dist/index.min.js +3 -3
- package/package.json +9 -9
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2015-
|
|
3
|
+
Copyright (c) 2015-2026 Andrew Caires (https://github.com/andrewcaires)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/fetch v1.
|
|
2
|
+
* @andrewcaires/fetch v1.2.0
|
|
3
3
|
* Plugin for fetch api
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2026 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
"use strict";var t=require("@andrewcaires/utils.js");function e(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 n={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:1e4},null!=t?t:{})}delete(t,n){return e(this,void 0,void 0,(function*(){return this.
|
|
7
|
+
"use strict";var t=require("@andrewcaires/utils.js");function e(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 n={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{on(t,e){return super.on(t,e)}constructor(t){super(),this._options=Object.assign({headers:{},timeout:1e4},null!=t?t:{})}delete(t,n){return e(this,void 0,void 0,(function*(){return this.request({method:"delete",path:t,query:n})}))}static delete(t,n,o){return e(this,void 0,void 0,(function*(){return new r(o).delete(t,n)}))}get(t,n){return e(this,void 0,void 0,(function*(){return this.request({method:"get",path:t,query:n})}))}static get(t,n,o){return e(this,void 0,void 0,(function*(){return new r(o).get(t,n)}))}head(t,n){return e(this,void 0,void 0,(function*(){return this.request({method:"head",path:t,query:n})}))}static head(t,n,o){return e(this,void 0,void 0,(function*(){return new r(o).head(t,n)}))}options(t,n){return e(this,void 0,void 0,(function*(){return this.request({method:"options",path:t,query:n})}))}static options(t,n,o){return e(this,void 0,void 0,(function*(){return new r(o).options(t,n)}))}patch(t,n,r){return e(this,void 0,void 0,(function*(){return this.request({method:"patch",path:t,body:n,query:r})}))}static patch(t,n,o,i){return e(this,void 0,void 0,(function*(){return new r(i).patch(t,n,o)}))}post(t,n,r){return e(this,void 0,void 0,(function*(){return this.request({method:"post",path:t,body:n,query:r})}))}static post(t,n,o,i){return e(this,void 0,void 0,(function*(){return new r(i).post(t,n,o)}))}put(t,n,r){return e(this,void 0,void 0,(function*(){return this.request({method:"put",path:t,body:n,query:r})}))}static put(t,n,o,i){return e(this,void 0,void 0,(function*(){return new r(i).put(t,n,o)}))}request(t){return e(this,void 0,void 0,(function*(){const e=this._input(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,n){return e(this,void 0,void 0,(function*(){return new r(n).request(t)}))}_body(e){const n=e instanceof Blob,r=e instanceof FormData,o=e instanceof URLSearchParams,i=!(n||r||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(),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:{})}_input({url:t,path:e,query:n,method:r,body:o,headers:i,timeout:s,credentials:a}){t=this._url(t,e,n),r=r.toUpperCase(),i=this._headers(i);const{json:u,parse:d}=this._body(o);o&&u&&!i["Content-Type"]&&(i["Content-Type"]="application/json");const c=this._signal(s);return a||(a=this._options.credentials),{url:t,method:r,body:d,headers:i,signal:c,credentials:a}}_signal(e){const n=new AbortController;return t.isUndefined(e)&&(e=this._options.timeout),e&&setTimeout((()=>n.abort()),e),n.signal}_status(t){var e;return t.statusText||(null!==(e=n[t.status])&&void 0!==e?e:"ERROR")}_url(e,n,r){const o=new URL(null!=n?n:"",null!=e?e:this._options.url);return r&&t.forEachKey(r,((t,e)=>o.searchParams.set(e,t))),o.toString()}}exports.Fetch=r,exports.FetchStatusText=n;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/fetch v1.
|
|
2
|
+
* @andrewcaires/fetch v1.2.0
|
|
3
3
|
* Plugin for fetch api
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2026 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
import { TypeObjectString, TypeNullable, EventEmitter } from '@andrewcaires/utils.js';
|
|
7
|
+
import { TypeObjectString, TypeNullable, EventEmitter, IEventDisposable } from '@andrewcaires/utils.js';
|
|
8
8
|
|
|
9
9
|
interface FetchBody {
|
|
10
10
|
json: boolean;
|
|
11
11
|
parse: any;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
type FetchCredentials = "include" | "omit" | "same-origin";
|
|
15
|
+
|
|
14
16
|
type FetchHeaders = TypeObjectString;
|
|
15
17
|
|
|
16
18
|
interface FetchOptions {
|
|
17
19
|
url?: string;
|
|
18
20
|
headers?: FetchHeaders;
|
|
19
21
|
timeout?: number;
|
|
22
|
+
credentials?: FetchCredentials;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
type FetchQuery = TypeNullable<TypeObjectString>;
|
|
@@ -29,6 +32,7 @@ interface FetchParams {
|
|
|
29
32
|
body?: any;
|
|
30
33
|
headers?: FetchHeaders;
|
|
31
34
|
timeout?: number;
|
|
35
|
+
credentials?: FetchCredentials;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
interface FetchRequest {
|
|
@@ -37,40 +41,42 @@ interface FetchRequest {
|
|
|
37
41
|
body: any;
|
|
38
42
|
signal: AbortSignal;
|
|
39
43
|
headers: FetchHeaders;
|
|
44
|
+
credentials?: FetchCredentials;
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
interface FetchResponse {
|
|
43
|
-
data
|
|
47
|
+
interface FetchResponse<T = any> {
|
|
48
|
+
data: T;
|
|
44
49
|
error?: string;
|
|
45
50
|
raw?: Response;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
declare class Fetch extends EventEmitter {
|
|
49
54
|
private _options;
|
|
55
|
+
on(_event: "before", _callback: (_request: FetchRequest) => void): IEventDisposable;
|
|
56
|
+
on(_event: "complete", _callback: (_response: FetchResponse) => void): IEventDisposable;
|
|
57
|
+
on(_event: "error", _callback: (_error: any) => void): IEventDisposable;
|
|
50
58
|
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>;
|
|
59
|
+
delete<T = any>(path: string, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
60
|
+
static delete<T = any>(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
61
|
+
get<T = any>(path: string, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
62
|
+
static get<T = any>(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
63
|
+
head<T = any>(path: string, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
64
|
+
static head<T = any>(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
65
|
+
options<T = any>(path: string, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
66
|
+
static options<T = any>(path: string, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
67
|
+
patch<T = any>(path: string, body?: any, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
68
|
+
static patch<T = any>(path: string, body?: any, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
69
|
+
post<T = any>(path: string, body?: any, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
70
|
+
static post<T = any>(path: string, body?: any, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
71
|
+
put<T = any>(path: string, body?: any, query?: FetchQuery): Promise<FetchResponse<T>>;
|
|
72
|
+
static put<T = any>(path: string, body?: any, query?: FetchQuery, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
73
|
+
request<T = any>(params: FetchParams): Promise<FetchResponse<T>>;
|
|
74
|
+
static request<T = any>(params: FetchParams, options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
69
75
|
private _body;
|
|
70
76
|
private _data;
|
|
71
77
|
private _header;
|
|
72
78
|
private _headers;
|
|
73
|
-
private
|
|
79
|
+
private _input;
|
|
74
80
|
private _signal;
|
|
75
81
|
private _status;
|
|
76
82
|
private _url;
|
|
@@ -78,4 +84,5 @@ declare class Fetch extends EventEmitter {
|
|
|
78
84
|
|
|
79
85
|
declare const FetchStatusText: TypeObjectString;
|
|
80
86
|
|
|
81
|
-
export { Fetch,
|
|
87
|
+
export { Fetch, FetchStatusText };
|
|
88
|
+
export type { FetchBody, FetchCredentials, 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.2.0
|
|
3
3
|
* Plugin for fetch api
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2026 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{on(t,e){return super.on(t,e)}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._input(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:{})}_input({url:t,path:e,query:n,method:r,body:o,headers:i,timeout:s,credentials:a}){t=this._url(t,e,n),r=r.toUpperCase(),i=this._headers(i);const{json:u,parse:d}=this._body(o);o&&u&&!i["Content-Type"]&&(i["Content-Type"]="application/json");const h=this._signal(s);return a||(a=this._options.credentials),{url:t,method:r,body:d,headers:i,signal:h,credentials:a}}_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.2.0
|
|
3
3
|
* Plugin for fetch api
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2026 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{
|
|
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{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 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{on(t,e){return super.on(t,e)}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._input(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:{})}_input({url:t,path:e,query:n,method:r,body:o,headers:i,timeout:s,credentials:a}){t=this._url(t,e,n),r=r.toUpperCase(),i=this._headers(i);const{json:u,parse:d}=this._body(o);o&&u&&!i["Content-Type"]&&(i["Content-Type"]="application/json");const c=this._signal(s);return a||(a=this._options.credentials),{url:t,method:r,body:d,headers:i,signal:c,credentials:a}}_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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrewcaires/fetch",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Plugin for fetch api",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs.js",
|
|
@@ -37,16 +37,16 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/andrewcaires/npm#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@andrewcaires/utils.js": "^0.4.
|
|
40
|
+
"@andrewcaires/utils.js": "^0.4.20"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@rollup/plugin-commonjs": "^
|
|
43
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
44
44
|
"@rollup/plugin-terser": "^0.4.4",
|
|
45
|
-
"@rollup/plugin-typescript": "^12.
|
|
46
|
-
"eslint": "^9.
|
|
47
|
-
"rollup": "^4.
|
|
48
|
-
"rollup-plugin-dts": "^6.
|
|
49
|
-
"tslib": "^2.
|
|
50
|
-
"typescript-eslint": "^8.
|
|
45
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
46
|
+
"eslint": "^9.39.2",
|
|
47
|
+
"rollup": "^4.55.1",
|
|
48
|
+
"rollup-plugin-dts": "^6.3.0",
|
|
49
|
+
"tslib": "^2.8.1",
|
|
50
|
+
"typescript-eslint": "^8.53.0"
|
|
51
51
|
}
|
|
52
52
|
}
|