@whitesev/utils 1.3.6 → 1.3.8
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 +24 -0
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +24 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +24 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +24 -0
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +24 -0
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +24 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Utils.d.ts +8 -0
- package/package.json +1 -1
- package/src/Utils.ts +27 -0
package/dist/index.iife.js
CHANGED
|
@@ -6060,6 +6060,30 @@ var Utils = (function () {
|
|
|
6060
6060
|
createUtils(option) {
|
|
6061
6061
|
return new Utils(option);
|
|
6062
6062
|
}
|
|
6063
|
+
/**
|
|
6064
|
+
* 将对象转换为FormData
|
|
6065
|
+
* @param data 待转换的对象
|
|
6066
|
+
* @param isEncode 是否对值为string进行编码转换(encodeURIComponent)
|
|
6067
|
+
*/
|
|
6068
|
+
toFormData(data, isEncode = false) {
|
|
6069
|
+
const formData = new FormData();
|
|
6070
|
+
Object.keys(data).forEach((key) => {
|
|
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
|
+
}
|
|
6078
|
+
if (value instanceof File) {
|
|
6079
|
+
formData.append(key, value, value.name);
|
|
6080
|
+
}
|
|
6081
|
+
else {
|
|
6082
|
+
formData.append(key, value);
|
|
6083
|
+
}
|
|
6084
|
+
});
|
|
6085
|
+
return formData;
|
|
6086
|
+
}
|
|
6063
6087
|
}
|
|
6064
6088
|
let utils = new Utils();
|
|
6065
6089
|
|