Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emmanuelallan/formdata-to-from-object
https://github.com/emmanuelallan/formdata-to-from-object
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/emmanuelallan/formdata-to-from-object
- Owner: emmanuelallan
- Created: 2024-08-08T10:34:07.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-13T09:49:40.000Z (5 months ago)
- Last Synced: 2025-01-14T06:28:22.877Z (8 days ago)
- Language: TypeScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FormData Utils
A utility library to convert FormData to and from JavaScript objects.
### Installation
```bash
npm install formdata-object-utils```### Usage
Importing the library
```ts
import FormDataUtils from 'formdata-object-utils';
```### Converting FormData to an Object
```ts
const formData = new FormData();
formData.append('name', 'John Doe');
formData.append('age', '30');const obj = FormDataUtils.toObj(formData);
console.log(obj); // { name: 'John Doe', age: '30' }
```### Converting an Object to FormData
```ts
const obj = { name: 'John Doe', age: '30' };
const formData = FormDataUtils.fromObj(obj);// Now formData can be used as FormData object
```### API
`toObj(source: FormData): FormDataObject`
Converts a `FormData` object to a plain JavaScript object.`fromObj(obj: FormDataObject): FormData`
Converts a plain JavaScript object to a `FormData` object.### License
This project is licensed under the MIT License.### **Optional: Adding `engines` Field in `package.json`**
To specify the Node.js version and package managers supported, you can add an `engines` field in your `package.json`:```json
{
"engines": {
"node": ">=12",
"npm": ">=6",
"yarn": ">=1.22",
"pnpm": ">=6",
"bun": ">=0.1"
}
}