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