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