react-native-formdata-helper
Version:
A simple, reusable helper library for handling FormData requests in React Native.
21 lines (18 loc) • 450 B
text/typescript
export const serializeFormData = (formData: FormData) => {
const jsonData: Record<string, any> = {};
formData.forEach((value: any, key: string) => {
if (value?.uri) {
if (!jsonData[key]) {
jsonData[key] = [];
}
jsonData[key].push({
uri: value.uri,
name: value.name,
type: value.type,
});
} else {
jsonData[key] = value;
}
});
return jsonData;
};