add test, update tags, update description

This commit is contained in:
Nikita
2019-03-15 12:54:57 +03:00
parent 5939e3fb27
commit c7fb5aa189
10 changed files with 123 additions and 59 deletions

View File

@ -1,6 +1,6 @@
### formToObject
Serializes a form into an object.
Encode a set of form elements as a `object`.
First we transform the `form` into `FormData`, then we convert it into an `array` and from the `array` we collect an `object`
@ -13,13 +13,6 @@ const formToObject = form =>
}), {})
```
```html
<form id="form">
<input name="email" type="email" />
<input name="name" />
</form>
```
```js
formToObject(document.querySelector('#form')) // { email: 'test@email.com', name: 'Test Name' }
```

View File

@ -1,6 +1,6 @@
### serializeForm
Serializes a form into an object.
Encode a set of form elements as a query string.
First we transform the `form` into `FormData`, then we convert it into an `array` and from the `array` we collect an `query string`
@ -9,13 +9,6 @@ const serializeForm = form =>
Array.from(new FormData(form), field => field.map(encodeURIComponent).join('=')).join('&')
```
```html
<form id="form">
<input name="email" type="email" />
<input name="name" />
</form>
```
```js
serializeForm(document.querySelector('#form')) // email=test%40email.com&name=Test%20Name
```