@aiszlab/relax 1.2.41 → 1.2.42
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.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils/to-form-data/index.js +23 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -41,3 +41,4 @@ export { debounce } from './utils/debounce/index.js';
|
|
|
41
41
|
export { toArray } from './utils/to-array/index.js';
|
|
42
42
|
export { toFunction } from './utils/to-function.js';
|
|
43
43
|
export { exclude } from './utils/exclude/index.js';
|
|
44
|
+
export { toFormData } from './utils/to-form-data/index.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* convert to formData
|
|
4
|
+
*/
|
|
5
|
+
var toFormData = function toFormData(data) {
|
|
6
|
+
var formData = new FormData();
|
|
7
|
+
Object.keys(data).forEach(function (key) {
|
|
8
|
+
var value = data[key];
|
|
9
|
+
// support key-value array data
|
|
10
|
+
if (Array.isArray(value)) {
|
|
11
|
+
value.forEach(function (item) {
|
|
12
|
+
// { list: [ 11, 22 ] }
|
|
13
|
+
// formData.append('list[]', 11);
|
|
14
|
+
formData.append("".concat(key, "[]"), item);
|
|
15
|
+
});
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
formData.append(key, value);
|
|
19
|
+
});
|
|
20
|
+
return formData;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { toFormData };
|