Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/linusu/node-append-field
W3C HTML JSON form compliant field appender
https://github.com/linusu/node-append-field
Last synced: 11 days ago
JSON representation
W3C HTML JSON form compliant field appender
- Host: GitHub
- URL: https://github.com/linusu/node-append-field
- Owner: LinusU
- License: mit
- Created: 2015-05-03T14:14:49.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-11-22T02:22:51.000Z (almost 2 years ago)
- Last Synced: 2024-10-24T07:38:22.222Z (20 days ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# `append-field`
A [W3C HTML JSON forms spec](http://www.w3.org/TR/html-json-forms/) compliant
field appender (for lack of a better name). Useful for people implementing
`application/x-www-form-urlencoded` and `multipart/form-data` parsers.It works best on objects created with `Object.create(null)`. Otherwise it might
conflict with variables from the prototype (e.g. `hasOwnProperty`).## Installation
```sh
npm install --save append-field
```## Usage
```javascript
import appendField from 'append-field'const obj = Object.create(null)
appendField(obj, 'pets[0][species]', 'Dahut')
appendField(obj, 'pets[0][name]', 'Hypatia')
appendField(obj, 'pets[1][species]', 'Felis Stultus')
appendField(obj, 'pets[1][name]', 'Billie')console.log(obj)
``````text
{ pets:
[ { species: 'Dahut', name: 'Hypatia' },
{ species: 'Felis Stultus', name: 'Billie' } ] }
```## API
### `appendField(store, key, value)`
- `store` (`object`, required)
- `key` (`string`, required)
- `value` (`any`, required)Adds the field named `key` with the value `value` to the object `store`.
## License
MIT