befly-shared 2.0.14 → 2.0.15

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/package.json +7 -7
  2. package/utils/createHttp.js +19 -17
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "befly-shared",
3
- "version": "2.0.14",
3
+ "version": "2.0.15",
4
+ "gitHead": "70c48ac058875255ac8b54c5f4b5987b997c3bfd",
4
5
  "private": false,
5
6
  "description": "Befly Shared - 通用工具函数库",
7
+ "files": [
8
+ "utils/",
9
+ "package.json"
10
+ ],
6
11
  "type": "module",
7
12
  "exports": {
8
13
  "./*": {
@@ -10,16 +15,11 @@
10
15
  "default": "./utils/*.js"
11
16
  }
12
17
  },
13
- "files": [
14
- "utils/",
15
- "package.json"
16
- ],
17
18
  "publishConfig": {
18
19
  "access": "public",
19
20
  "registry": "https://registry.npmjs.org"
20
21
  },
21
22
  "engines": {
22
23
  "bun": ">=1.3.0"
23
- },
24
- "gitHead": "70c48ac058875255ac8b54c5f4b5987b997c3bfd"
24
+ }
25
25
  }
@@ -1,25 +1,27 @@
1
- export function createHttp(options) {
2
- const config = options && typeof options === "object" ? options : {};
3
- const apiPath = typeof config.apiPath === "string" ? config.apiPath : "";
4
- const getToken = typeof config.getToken === "function" ? config.getToken : () => "";
5
- const onReturn = typeof config.onReturn === "function" ? config.onReturn : null;
1
+ function shouldDropHttpValue(key, value, dropList, dropKeyMap) {
2
+ for (const dropValue of dropList) {
3
+ if (Object.is(value, dropValue)) {
4
+ return true;
5
+ }
6
+ }
6
7
 
7
- function shouldDrop(key, value, dropList, dropKeyMap) {
8
- for (const dropValue of dropList) {
8
+ if (Array.isArray(dropKeyMap[key])) {
9
+ for (const dropValue of dropKeyMap[key]) {
9
10
  if (Object.is(value, dropValue)) {
10
11
  return true;
11
12
  }
12
13
  }
13
- if (Array.isArray(dropKeyMap[key])) {
14
- for (const dropValue of dropKeyMap[key]) {
15
- if (Object.is(value, dropValue)) {
16
- return true;
17
- }
18
- }
19
- }
20
- return false;
21
14
  }
22
15
 
16
+ return false;
17
+ }
18
+
19
+ export function createHttp(options) {
20
+ const config = options && typeof options === "object" ? options : {};
21
+ const apiPath = typeof config.apiPath === "string" ? config.apiPath : "";
22
+ const getToken = typeof config.getToken === "function" ? config.getToken : () => "";
23
+ const onReturn = typeof config.onReturn === "function" ? config.onReturn : null;
24
+
23
25
  return async function requestPost(url, data, dropValues, dropKeyValue) {
24
26
  try {
25
27
  const fullUrl = /^https?:\/\//i.test(url) ? url : `${apiPath}${url}`;
@@ -32,7 +34,7 @@ export function createHttp(options) {
32
34
  for (const entry of payloadData.entries()) {
33
35
  const key = entry[0];
34
36
  const value = entry[1];
35
- if (!shouldDrop(key, value, dropList, dropKeyMap)) {
37
+ if (!shouldDropHttpValue(key, value, dropList, dropKeyMap)) {
36
38
  nextForm.append(key, value);
37
39
  }
38
40
  }
@@ -41,7 +43,7 @@ export function createHttp(options) {
41
43
  const nextData = {};
42
44
  for (const key of Object.keys(payloadData)) {
43
45
  const value = payloadData[key];
44
- if (!shouldDrop(key, value, dropList, dropKeyMap)) {
46
+ if (!shouldDropHttpValue(key, value, dropList, dropKeyMap)) {
45
47
  nextData[key] = value;
46
48
  }
47
49
  }