Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smeijer/form-data-kit
a lib to parse, stringify, and expand FormData
https://github.com/smeijer/form-data-kit
Last synced: 16 days ago
JSON representation
a lib to parse, stringify, and expand FormData
- Host: GitHub
- URL: https://github.com/smeijer/form-data-kit
- Owner: smeijer
- License: mit
- Created: 2024-05-06T12:21:39.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-09-18T11:09:03.000Z (about 2 months ago)
- Last Synced: 2024-10-12T09:17:50.882Z (about 1 month ago)
- Language: TypeScript
- Size: 67.4 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
Awesome Lists containing this project
README
# form-data-kit
> library to parse, stringify, and expand FormData
## Install
```sh
npm install form-data-kit
```## Usage
```ts
import { parse, stringify, expand } from 'form-data-kit';parse(query: string): FormData
stringify(formData: FormData): string
expand(formData: FormData): object
```## Parse
Parse takes a search param / query string, like the one from an url, and returns FormData
```js
import { parse } from "form-data-kit";parse("one=foo&two=bar");
// FormData {
// [Symbol(state)]: [ { name: 'one', value: 'foo' }, { name: 'two', value: 'bar' } ]
// }
```## Stringify
Parse takes FormData, and returns a search param / query string
```ts
import { stringify } from "form-data-kit";const formData = new FormData();
formData.set("one", "foo");
formData.set("two", "bar");stringify(formData);
// one=foo&two=bar
```## Expand
Expands formData into an object. This method supports nesting, using `.` and `[number]` syntax.
```ts
import { expand } from "form-data-kit";const formData = new FormData();
formData.append("one", "1");
formData.append("two", "2");
formData.append("nested.three", "3");
formData.append("array[0]", "4");
formData.append("array[1].five", "5");expand(formData);
// {
// one: '1',
// two: '2',
// nested: {
// three: '3',
// },
// array: ['4', { five: '5' }],
// }
```