append-field
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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

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)
{ 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

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i append-field

    Weekly Downloads

    4,446,568

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    6.82 kB

    Total Files

    9

    Last publish

    Collaborators

    • linusu