1 export const serializeFormData = (data: { [key: string]: any }): FormData => {
2 const formData = new FormData();
3 Object.keys(data).forEach((key) => {
4 if (Array.isArray(data[key])) {
5 data[key].forEach((val: any) => formData.append(key, val));
7 formData.append(key, data[key]);
13 export type FetchDataType = 'json' | 'form' | 'protobuf';
14 export const serializeData = (data: any, input: FetchDataType): Pick<RequestInit, 'body' | 'headers'> => {
18 if (input === 'json') {
20 body: JSON.stringify(data),
22 'content-type': 'application/json',
26 if (input === 'form') {
28 body: serializeFormData(data),
31 if (input === 'protobuf') {
35 'content-type': 'application/x-protobuf',