@whitesev/utils 1.3.7 → 1.3.8

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.
@@ -1806,10 +1806,12 @@ declare class Utils {
1806
1806
  createUtils(option?: UtilsCoreOption): Utils;
1807
1807
  /**
1808
1808
  * 将对象转换为FormData
1809
+ * @param data 待转换的对象
1810
+ * @param isEncode 是否对值为string进行编码转换(encodeURIComponent)
1809
1811
  */
1810
1812
  toFormData(data: {
1811
- [key: string]: string | Blob | File;
1812
- }): FormData;
1813
+ [key: string]: string | Blob | File | number;
1814
+ }, isEncode?: boolean): FormData;
1813
1815
  }
1814
1816
  declare let utils: Utils;
1815
1817
  export { utils as Utils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "1.3.7",
3
+ "version": "1.3.8",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/node/index.esm.js",
package/src/Utils.ts CHANGED
@@ -4898,11 +4898,22 @@ class Utils {
4898
4898
 
4899
4899
  /**
4900
4900
  * 将对象转换为FormData
4901
+ * @param data 待转换的对象
4902
+ * @param isEncode 是否对值为string进行编码转换(encodeURIComponent)
4901
4903
  */
4902
- toFormData(data: { [key: string]: string | Blob | File }) {
4904
+ toFormData(
4905
+ data: { [key: string]: string | Blob | File | number },
4906
+ isEncode: boolean = false
4907
+ ) {
4903
4908
  const formData = new FormData();
4904
4909
  Object.keys(data).forEach((key) => {
4905
4910
  let value = data[key];
4911
+ if (typeof value === "number") {
4912
+ value = value.toString();
4913
+ }
4914
+ if (isEncode && typeof value === "string") {
4915
+ value = encodeURIComponent(value);
4916
+ }
4906
4917
  if (value instanceof File) {
4907
4918
  formData.append(key, value, value.name);
4908
4919
  } else {