kbfetch 1.0.4 → 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/README.md CHANGED
@@ -19,6 +19,14 @@ kbfetch.post('https://api.example.com/data', { id: 1 }, { params: { qa: 1 } })
19
19
  kbfetch.p('https://api.example.com/data', { params: { qa: 1 }, body: { id: 1 } })
20
20
  ```
21
21
 
22
+ path参数
23
+
24
+ ```js
25
+ kbfetch.get('https://baidu.com/:a/:b', { a: 1, b: 2 }).then(console.log)
26
+ kbfetch.post('https://baidu.com/:a/:b', { k: 2 }, { params: { a: 1, b: 2 } }).then(console.log)
27
+ kbfetch.p('https://api.example.com/:a/:b', { params: { a: 1, b: 2 }, body: { id: 1 } })
28
+ ```
29
+
22
30
  发起 其他method 请求的示例:
23
31
 
24
32
  ```js
package/dist/index.js CHANGED
@@ -3,7 +3,14 @@ var help = {
3
3
  synthesizeUrlWithParams: (url, params) => {
4
4
  if (!params)
5
5
  return url;
6
- const [pre, originalQueryStr] = url.split("?");
6
+ let [pre, originalQueryStr] = url.split("?");
7
+ if (pre.includes("/:")) {
8
+ pre = pre.replace(/\/:([^\/]+)/g, (_, p) => {
9
+ const res = "/" + params[p];
10
+ delete params[p];
11
+ return res;
12
+ });
13
+ }
7
14
  const queryStr = Object.entries(params).map(([k, v]) => `${k}=${v}`).join("&");
8
15
  const fullQueryStr = [originalQueryStr, queryStr].filter(Boolean).join("&");
9
16
  return [pre, fullQueryStr].filter(Boolean).join("?");
@@ -16,7 +23,10 @@ var help = {
16
23
  },
17
24
  obj2header: (obj) => {
18
25
  const headers = new Headers;
19
- Object.entries(obj).forEach(([k, v]) => headers.append(k, v));
26
+ Object.entries(obj).forEach((kv) => {
27
+ const [k, v] = kv.map((str) => typeof str !== "string" ? str : str.replace(/[\u4e00-\u9fa5]+/g, (v2) => encodeURI(v2)));
28
+ headers.append(k, v);
29
+ });
20
30
  return headers;
21
31
  },
22
32
  urlWithProtocol: (url) => url.startsWith("http://") || url.startsWith("https://"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kbfetch",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "devDependencies": {
@@ -21,11 +21,12 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "scripts": {
24
- "pub": "bun bld && bun tsc && npm publish --registry https://registry.npmjs.org/ && bun updatetaobao ",
24
+ "pub": "bun bld && bun tsc && npm publish --registry https://registry.npmjs.org/ ",
25
25
  "patch": "git stash && npm version patch && git stash pop",
26
26
  "updatetaobao": "cnpm sync kbfetch",
27
27
  "tsc": "tsc index.ts -d --emitDeclarationOnly --declarationDir ./dist/typings",
28
- "bld": "bun build ./index.ts --outdir ./dist"
28
+ "bld": "bun build ./index.ts --outdir ./dist",
29
+ "t":"bun t.ts"
29
30
  },
30
31
  "type": "module",
31
32
  "types": "./dist/typings/index.d.ts"