@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.
package/dist/index.esm.js CHANGED
@@ -6059,11 +6059,19 @@ class Utils {
6059
6059
  }
6060
6060
  /**
6061
6061
  * 将对象转换为FormData
6062
+ * @param data 待转换的对象
6063
+ * @param isEncode 是否对值为string进行编码转换(encodeURIComponent)
6062
6064
  */
6063
- toFormData(data) {
6065
+ toFormData(data, isEncode = false) {
6064
6066
  const formData = new FormData();
6065
6067
  Object.keys(data).forEach((key) => {
6066
6068
  let value = data[key];
6069
+ if (typeof value === "number") {
6070
+ value = value.toString();
6071
+ }
6072
+ if (isEncode && typeof value === "string") {
6073
+ value = encodeURIComponent(value);
6074
+ }
6067
6075
  if (value instanceof File) {
6068
6076
  formData.append(key, value, value.name);
6069
6077
  }