Metzploreur/node_modules/append-field
clement callaert ea7979b55b commit
2023-11-04 00:51:37 +01:00
..
lib commit 2023-11-04 00:51:37 +01:00
test commit 2023-11-04 00:51:37 +01:00
.npmignore commit 2023-11-04 00:51:37 +01:00
index.js commit 2023-11-04 00:51:37 +01:00
LICENSE commit 2023-11-04 00:51:37 +01:00
package.json commit 2023-11-04 00:51:37 +01:00
README.md commit 2023-11-04 00:51:37 +01:00

append-field

A W3C HTML JSON forms spec 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

npm install --save append-field

Usage

var appendField = require('append-field')
var 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)
{ pets:
   [ { species: 'Dahut', name: 'Hypatia' },
     { species: 'Felis Stultus', name: 'Billie' } ] }

API

appendField(store, key, value)

Adds the field named key with the value value to the object store.

License

MIT