@whitesev/utils 1.3.7 → 1.3.9

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.9",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/node/index.esm.js",
package/src/Utils.ts CHANGED
@@ -4724,6 +4724,9 @@ class Utils {
4724
4724
  if (typeof checkObj === "function") {
4725
4725
  obj = checkObj();
4726
4726
  }
4727
+ if (typeof obj !== "object") {
4728
+ return;
4729
+ }
4727
4730
  if (
4728
4731
  (typeof checkPropertyName === "function" && checkPropertyName(obj)) ||
4729
4732
  Reflect.has(obj, checkPropertyName as string)
@@ -4898,11 +4901,22 @@ class Utils {
4898
4901
 
4899
4902
  /**
4900
4903
  * 将对象转换为FormData
4904
+ * @param data 待转换的对象
4905
+ * @param isEncode 是否对值为string进行编码转换(encodeURIComponent)
4901
4906
  */
4902
- toFormData(data: { [key: string]: string | Blob | File }) {
4907
+ toFormData(
4908
+ data: { [key: string]: string | Blob | File | number },
4909
+ isEncode: boolean = false
4910
+ ) {
4903
4911
  const formData = new FormData();
4904
4912
  Object.keys(data).forEach((key) => {
4905
4913
  let value = data[key];
4914
+ if (typeof value === "number") {
4915
+ value = value.toString();
4916
+ }
4917
+ if (isEncode && typeof value === "string") {
4918
+ value = encodeURIComponent(value);
4919
+ }
4906
4920
  if (value instanceof File) {
4907
4921
  formData.append(key, value, value.name);
4908
4922
  } else {