@whitesev/utils 1.3.6 → 1.3.7

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.
@@ -1804,6 +1804,12 @@ declare class Utils {
1804
1804
  * @returns
1805
1805
  */
1806
1806
  createUtils(option?: UtilsCoreOption): Utils;
1807
+ /**
1808
+ * 将对象转换为FormData
1809
+ */
1810
+ toFormData(data: {
1811
+ [key: string]: string | Blob | File;
1812
+ }): FormData;
1807
1813
  }
1808
1814
  declare let utils: Utils;
1809
1815
  export { utils as Utils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/node/index.esm.js",
package/src/Utils.ts CHANGED
@@ -4895,6 +4895,22 @@ class Utils {
4895
4895
  createUtils(option?: UtilsCoreOption) {
4896
4896
  return new Utils(option);
4897
4897
  }
4898
+
4899
+ /**
4900
+ * 将对象转换为FormData
4901
+ */
4902
+ toFormData(data: { [key: string]: string | Blob | File }) {
4903
+ const formData = new FormData();
4904
+ Object.keys(data).forEach((key) => {
4905
+ let value = data[key];
4906
+ if (value instanceof File) {
4907
+ formData.append(key, value, value.name);
4908
+ } else {
4909
+ formData.append(key, value);
4910
+ }
4911
+ });
4912
+ return formData;
4913
+ }
4898
4914
  }
4899
4915
 
4900
4916
  let utils = new Utils();