kbfetch 0.0.6 → 0.0.7

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.js CHANGED
@@ -20,6 +20,11 @@ var help = {
20
20
  if (contentType.includes("application/json"))
21
21
  return res.json();
22
22
  return res.text();
23
+ },
24
+ obj2header: (obj) => {
25
+ const headers = new Headers;
26
+ Object.entries(obj).forEach(([k, v]) => headers.append(k, v));
27
+ return headers;
23
28
  }
24
29
  };
25
30
  var help_default = help;
@@ -35,8 +40,8 @@ var defaultKbFetch = {
35
40
  const _t = this;
36
41
  let { before = _t.before, ..._init } = init || {};
37
42
  _init = before(_init);
38
- let { parser = _t.parser, after = _t.after, baseUrl = _t.baseUrl, timeout = _t.timeout, ...requestInit } = _init;
39
- timeout && Object.assign(requestInit, { signal: help_default.createTimeoutSignal(timeout) });
43
+ let { parser = _t.parser, after = _t.after, baseUrl = _t.baseUrl, timeout = _t.timeout, headers = {}, ...requestInit } = _init;
44
+ timeout && Object.assign(requestInit, { signal: help_default.createTimeoutSignal(timeout), headers: help_default.obj2header(headers) });
40
45
  if (!url.startsWith("http://") && !url.startsWith("https://"))
41
46
  url = baseUrl + url;
42
47
  const response = fetch(url, requestInit).then(async (respnse) => {
@@ -4,17 +4,20 @@ type After = <T = any>(res: Promise<Response & {
4
4
  data: T;
5
5
  }>) => any;
6
6
  type _KbFetchInit = {
7
- timeout?: number;
8
7
  before?: Before;
9
8
  parser?: Parser;
10
9
  after?: After;
11
10
  baseUrl?: string;
12
11
  flags?: Record<string, any>;
13
12
  };
14
- export type KbFetchInit = Omit<RequestInit, 'timeout'> & _KbFetchInit;
13
+ export type KbFetchInit = Omit<RequestInit, 'timeout' | 'headers'> & {
14
+ timeout?: number;
15
+ headers?: Record<string, string>;
16
+ } & _KbFetchInit;
15
17
  declare const help: {
16
18
  synthesizeUrlWithParams: (url: string, params?: Record<string, any>) => string;
17
19
  createTimeoutSignal: (timeout: number) => AbortSignal;
18
20
  parseResBody: (res: Response) => Promise<any>;
21
+ obj2header: (obj: Record<string, string>) => Headers;
19
22
  };
20
23
  export default help;
@@ -9,8 +9,10 @@ declare const defaultKbFetch: {
9
9
  timeout: number;
10
10
  do: <T = any>(url: string, init?: KbFetchInit) => Promise<any>;
11
11
  get: <T_1 = any>(url: string, params?: Record<string, any>, init?: KbFetchInit) => Promise<T_1>;
12
- g: <T_2 = any>(url: string, init?: Omit<RequestInit, "timeout"> & {
12
+ g: <T_2 = any>(url: string, init?: Omit<RequestInit, "timeout" | "headers"> & {
13
13
  timeout?: number;
14
+ headers?: Record<string, string>;
15
+ } & {
14
16
  before?: (init: KbFetchInit) => KbFetchInit;
15
17
  parser?: (res: Response) => any;
16
18
  after?: <T_3 = any>(res: Promise<Response & {
@@ -33,8 +35,10 @@ export declare const createKbFetch: (config: Partial<typeof defaultKbFetch>) =>
33
35
  timeout: number;
34
36
  do: <T = any>(url: string, init?: KbFetchInit) => Promise<any>;
35
37
  get: <T_1 = any>(url: string, params?: Record<string, any>, init?: KbFetchInit) => Promise<T_1>;
36
- g: <T_2 = any>(url: string, init?: Omit<RequestInit, "timeout"> & {
38
+ g: <T_2 = any>(url: string, init?: Omit<RequestInit, "timeout" | "headers"> & {
37
39
  timeout?: number;
40
+ headers?: Record<string, string>;
41
+ } & {
38
42
  before?: (init: KbFetchInit) => KbFetchInit;
39
43
  parser?: (res: Response) => any;
40
44
  after?: <T_3 = any>(res: Promise<Response & {
@@ -57,8 +61,10 @@ declare const kbFetch: {
57
61
  timeout: number;
58
62
  do: <T = any>(url: string, init?: KbFetchInit) => Promise<any>;
59
63
  get: <T_1 = any>(url: string, params?: Record<string, any>, init?: KbFetchInit) => Promise<T_1>;
60
- g: <T_2 = any>(url: string, init?: Omit<RequestInit, "timeout"> & {
64
+ g: <T_2 = any>(url: string, init?: Omit<RequestInit, "timeout" | "headers"> & {
61
65
  timeout?: number;
66
+ headers?: Record<string, string>;
67
+ } & {
62
68
  before?: (init: KbFetchInit) => KbFetchInit;
63
69
  parser?: (res: Response) => any;
64
70
  after?: <T_3 = any>(res: Promise<Response & {
@@ -82,8 +88,10 @@ export declare const afetch: {
82
88
  timeout: number;
83
89
  do: <T = any>(url: string, init?: KbFetchInit) => Promise<any>;
84
90
  get: <T_1 = any>(url: string, params?: Record<string, any>, init?: KbFetchInit) => Promise<T_1>;
85
- g: <T_2 = any>(url: string, init?: Omit<RequestInit, "timeout"> & {
91
+ g: <T_2 = any>(url: string, init?: Omit<RequestInit, "timeout" | "headers"> & {
86
92
  timeout?: number;
93
+ headers?: Record<string, string>;
94
+ } & {
87
95
  before?: (init: KbFetchInit) => KbFetchInit;
88
96
  parser?: (res: Response) => any;
89
97
  after?: <T_3 = any>(res: Promise<Response & {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./dist/index.js",
4
4
  "module": "./dist/index.js",
5
5
  "type": "module",
6
- "version": "0.0.6",
6
+ "version": "0.0.7",
7
7
  "license": "MIT",
8
8
  "types": "./dist/typings/index.d.ts",
9
9
  "files": [