
This is a collection of functions for working with FormData objects.
The serializeFormData function serializes an object into a FormData object.
import { serializeFormData } from '@aracna/core';
const person = {
age: 20,
features: {
eyes: 'Brown',
height: 175
},
name: 'John',
picture: new Blob([])
};
const data = serializeFormData(person);
// will log "20"
console.log(data.get('age'));
// will log "{ "eyes": "Brown", "height": 175 }"
console.log(data.get('features'));
// will log "John"
console.log(data.get('name'));
// will log Blob
console.log(data.get('picture'));The deserializeFormData function deserializes a FormData object into an object.
import { deserializeFormData } from '@aracna/core';
const data = new FormData();
data.append('age', '20');
data.append('features', JSON.stringify({ eyes: 'Brown', height: 175 }));
data.append('name', 'John');
data.append('picture', new Blob([]));
// will log { age: 20, features: { eyes: "Brown", height: 175 }, name: "John", picture: Blob }
console.log(deserializeFormData(data));