kbfetch 2.1.1 → 2.1.2-beta.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.
Files changed (2) hide show
  1. package/dist/index.js +30 -27
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -56,34 +56,37 @@ var defaultKbFetch = {
56
56
  const _init = Object.assign(defOpts, init);
57
57
  help_default.objSetDefVal(_init, "headers", baseHeaders);
58
58
  help_default.objSetDefVal(_init, "params", baseParams);
59
- let { parser, after, timeout, canAbort, ...requestInit } = _init.before(_init) || _init;
60
- let abortController;
61
- let timeoutIns;
62
- if (timeout > 0 || canAbort) {
63
- abortController = new AbortController;
64
- Object.assign(requestInit, { signal: abortController.signal });
65
- if (timeout >= 0) {
66
- abortController.signal.onabort = () => clearTimeout(timeoutIns);
67
- timeoutIns = setTimeout(() => {
68
- abortController.abort();
69
- }, timeout);
59
+ const core = async () => {
60
+ let { parser, after, timeout, canAbort, ...requestInit } = await _init.before(_init) || _init;
61
+ let abortController;
62
+ let timeoutIns;
63
+ if (timeout > 0 || canAbort) {
64
+ abortController = new AbortController;
65
+ Object.assign(requestInit, { signal: abortController.signal });
66
+ if (timeout >= 0) {
67
+ abortController.signal.onabort = () => clearTimeout(timeoutIns);
68
+ timeoutIns = setTimeout(() => {
69
+ abortController.abort();
70
+ }, timeout);
71
+ }
70
72
  }
71
- }
72
- if (requestInit.params)
73
- url = help_default.synthesizeUrlWithParams(url, requestInit.params);
74
- if (requestInit.body && requestInit.body.constructor.name === "Object" && requestInit.headers?.["Content-Type"] !== "application/json") {
75
- requestInit.headers ||= {};
76
- requestInit.headers["Content-Type"] = "application/json";
77
- baseBody && help_default.objSetDefVal(requestInit, "body", baseBody);
78
- requestInit.body = JSON.stringify(requestInit.body);
79
- }
80
- requestInit.headers && (requestInit.headers = help_default.obj2header(requestInit.headers));
81
- url = help_default.urlWithDomain(url) ? url : (baseUrl || "") + url;
82
- url = help_default.addProtocol(url) || url;
83
- const response = fetch(url, requestInit).then(async (respnse) => Object.assign(respnse, { data: await parser(respnse) })).finally(() => clearTimeout(timeoutIns));
84
- return Object.assign(after(response, { url, init }), {
85
- abort: () => abortController?.abort()
86
- });
73
+ if (requestInit.params)
74
+ url = help_default.synthesizeUrlWithParams(url, requestInit.params);
75
+ if (requestInit.body && requestInit.body.constructor.name === "Object" && requestInit.headers?.["Content-Type"] !== "application/json") {
76
+ requestInit.headers ||= {};
77
+ requestInit.headers["Content-Type"] = "application/json";
78
+ baseBody && help_default.objSetDefVal(requestInit, "body", baseBody);
79
+ requestInit.body = JSON.stringify(requestInit.body);
80
+ }
81
+ requestInit.headers && (requestInit.headers = help_default.obj2header(requestInit.headers));
82
+ url = help_default.urlWithDomain(url) ? url : (baseUrl || "") + url;
83
+ url = help_default.addProtocol(url) || url;
84
+ const response = fetch(url, requestInit).then(async (respnse) => Object.assign(respnse, { data: await parser(respnse) })).finally(() => clearTimeout(timeoutIns));
85
+ return Object.assign(after(response, { url, init }), {
86
+ abort: () => abortController?.abort()
87
+ });
88
+ };
89
+ return core();
87
90
  },
88
91
  get: function(url, params, init) {
89
92
  params && (init ||= {}, init.params = params);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "kbfetch",
3
- "version": "2.1.1",
3
+ "version": "2.1.2-beta.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "devDependencies": {
7
7
  "@types/node": "^20.14.10",
8
8
  "bun-types": "latest",
9
- "typescript": "^5.5.3"
9
+ "typescript": "^6.0.3"
10
10
  },
11
11
  "peerDependencies": {
12
12
  "typescript": "^5.0.0"
@@ -21,12 +21,12 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "scripts": {
24
- "pub": "bun bld && bun tsc && npm publish --registry https://registry.npmjs.org/ ",
24
+ "pub": "bun bld && bun tsc && npm publish --tag beta --registry https://registry.npmjs.org/ ",
25
25
  "patch": "git stash && npm version patch && git stash pop",
26
26
  "updatetaobao": "cnpm sync kbfetch",
27
- "tsc": "tsc index.ts -d --emitDeclarationOnly --declarationDir ./dist/typings",
27
+ "tsc": "tsc -d --emitDeclarationOnly --declarationDir ./dist/typings",
28
28
  "bld": "bun build ./index.ts --outdir ./dist",
29
- "t":"bun t.ts"
29
+ "t": "bun t.ts"
30
30
  },
31
31
  "type": "module",
32
32
  "types": "./dist/typings/index.d.ts"