root / HServer / 00.Server / 00.Program / node_modules / append-field / README.md
이력 | 보기 | 이력해설 | 다운로드 (1016 Bytes)
1 |
# `append-field` |
---|---|
2 |
|
3 |
A [W3C HTML JSON forms spec](http://www.w3.org/TR/html-json-forms/) compliant |
4 |
field appender (for lack of a better name). Useful for people implementing |
5 |
`application/x-www-form-urlencoded` and `multipart/form-data` parsers. |
6 |
|
7 |
It works best on objects created with `Object.create(null)`. Otherwise it might |
8 |
conflict with variables from the prototype (e.g. `hasOwnProperty`). |
9 |
|
10 |
## Installation |
11 |
|
12 |
```sh |
13 |
npm install --save append-field |
14 |
``` |
15 |
|
16 |
## Usage |
17 |
|
18 |
```javascript |
19 |
var appendField = require('append-field') |
20 |
var obj = Object.create(null) |
21 |
|
22 |
appendField(obj, 'pets[0][species]', 'Dahut') |
23 |
appendField(obj, 'pets[0][name]', 'Hypatia') |
24 |
appendField(obj, 'pets[1][species]', 'Felis Stultus') |
25 |
appendField(obj, 'pets[1][name]', 'Billie') |
26 |
|
27 |
console.log(obj) |
28 |
``` |
29 |
|
30 |
```text |
31 |
{ pets: |
32 |
[ { species: 'Dahut', name: 'Hypatia' }, |
33 |
{ species: 'Felis Stultus', name: 'Billie' } ] } |
34 |
``` |
35 |
|
36 |
## API |
37 |
|
38 |
### `appendField(store, key, value)` |
39 |
|
40 |
Adds the field named `key` with the value `value` to the object `store`. |
41 |
|
42 |
## License |
43 |
|
44 |
MIT |