@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.amd.js +12 -1
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +12 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +12 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +12 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +12 -1
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +12 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Utils.d.ts +4 -2
- package/package.json +1 -1
- package/src/Utils.ts +15 -1
package/dist/src/Utils.d.ts
CHANGED
|
@@ -1806,10 +1806,12 @@ declare class Utils {
|
|
|
1806
1806
|
createUtils(option?: UtilsCoreOption): Utils;
|
|
1807
1807
|
/**
|
|
1808
1808
|
* 将对象转换为FormData
|
|
1809
|
+
* @param data 待转换的对象
|
|
1810
|
+
* @param isEncode 是否对值为string进行编码转换(encodeURIComponent)
|
|
1809
1811
|
*/
|
|
1810
1812
|
toFormData(data: {
|
|
1811
|
-
[key: string]: string | Blob | File;
|
|
1812
|
-
}): FormData;
|
|
1813
|
+
[key: string]: string | Blob | File | number;
|
|
1814
|
+
}, isEncode?: boolean): FormData;
|
|
1813
1815
|
}
|
|
1814
1816
|
declare let utils: Utils;
|
|
1815
1817
|
export { utils as Utils };
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -4724,6 +4724,9 @@ class Utils {
|
|
|
4724
4724
|
if (typeof checkObj === "function") {
|
|
4725
4725
|
obj = checkObj();
|
|
4726
4726
|
}
|
|
4727
|
+
if (typeof obj !== "object") {
|
|
4728
|
+
return;
|
|
4729
|
+
}
|
|
4727
4730
|
if (
|
|
4728
4731
|
(typeof checkPropertyName === "function" && checkPropertyName(obj)) ||
|
|
4729
4732
|
Reflect.has(obj, checkPropertyName as string)
|
|
@@ -4898,11 +4901,22 @@ class Utils {
|
|
|
4898
4901
|
|
|
4899
4902
|
/**
|
|
4900
4903
|
* 将对象转换为FormData
|
|
4904
|
+
* @param data 待转换的对象
|
|
4905
|
+
* @param isEncode 是否对值为string进行编码转换(encodeURIComponent)
|
|
4901
4906
|
*/
|
|
4902
|
-
toFormData(
|
|
4907
|
+
toFormData(
|
|
4908
|
+
data: { [key: string]: string | Blob | File | number },
|
|
4909
|
+
isEncode: boolean = false
|
|
4910
|
+
) {
|
|
4903
4911
|
const formData = new FormData();
|
|
4904
4912
|
Object.keys(data).forEach((key) => {
|
|
4905
4913
|
let value = data[key];
|
|
4914
|
+
if (typeof value === "number") {
|
|
4915
|
+
value = value.toString();
|
|
4916
|
+
}
|
|
4917
|
+
if (isEncode && typeof value === "string") {
|
|
4918
|
+
value = encodeURIComponent(value);
|
|
4919
|
+
}
|
|
4906
4920
|
if (value instanceof File) {
|
|
4907
4921
|
formData.append(key, value, value.name);
|
|
4908
4922
|
} else {
|