@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.
package/dist/index.esm.js CHANGED
@@ -5949,6 +5949,9 @@ class Utils {
5949
5949
  if (typeof checkObj === "function") {
5950
5950
  obj = checkObj();
5951
5951
  }
5952
+ if (typeof obj !== "object") {
5953
+ return;
5954
+ }
5952
5955
  if ((typeof checkPropertyName === "function" && checkPropertyName(obj)) ||
5953
5956
  Reflect.has(obj, checkPropertyName)) {
5954
5957
  isResolve = true;
@@ -6059,11 +6062,19 @@ class Utils {
6059
6062
  }
6060
6063
  /**
6061
6064
  * 将对象转换为FormData
6065
+ * @param data 待转换的对象
6066
+ * @param isEncode 是否对值为string进行编码转换(encodeURIComponent)
6062
6067
  */
6063
- toFormData(data) {
6068
+ toFormData(data, isEncode = false) {
6064
6069
  const formData = new FormData();
6065
6070
  Object.keys(data).forEach((key) => {
6066
6071
  let value = data[key];
6072
+ if (typeof value === "number") {
6073
+ value = value.toString();
6074
+ }
6075
+ if (isEncode && typeof value === "string") {
6076
+ value = encodeURIComponent(value);
6077
+ }
6067
6078
  if (value instanceof File) {
6068
6079
  formData.append(key, value, value.name);
6069
6080
  }