@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.umd.js CHANGED
@@ -5955,6 +5955,9 @@
5955
5955
  if (typeof checkObj === "function") {
5956
5956
  obj = checkObj();
5957
5957
  }
5958
+ if (typeof obj !== "object") {
5959
+ return;
5960
+ }
5958
5961
  if ((typeof checkPropertyName === "function" && checkPropertyName(obj)) ||
5959
5962
  Reflect.has(obj, checkPropertyName)) {
5960
5963
  isResolve = true;
@@ -6065,11 +6068,19 @@
6065
6068
  }
6066
6069
  /**
6067
6070
  * 将对象转换为FormData
6071
+ * @param data 待转换的对象
6072
+ * @param isEncode 是否对值为string进行编码转换(encodeURIComponent)
6068
6073
  */
6069
- toFormData(data) {
6074
+ toFormData(data, isEncode = false) {
6070
6075
  const formData = new FormData();
6071
6076
  Object.keys(data).forEach((key) => {
6072
6077
  let value = data[key];
6078
+ if (typeof value === "number") {
6079
+ value = value.toString();
6080
+ }
6081
+ if (isEncode && typeof value === "string") {
6082
+ value = encodeURIComponent(value);
6083
+ }
6073
6084
  if (value instanceof File) {
6074
6085
  formData.append(key, value, value.name);
6075
6086
  }