@multipart/append-field

[fork] W3C HTML JSON form compliant field appender Written In ES6 And Optimised With JavaScript Compiler.

Usage no npm install needed!

<script type="module">
  import multipartAppendField from 'https://cdn.skypack.dev/@multipart/append-field';
</script>

README

@goa/append-field

npm version

@goa/append-field is a fork of W3C HTML JSON form compliant field appender Written In ES6 And Optimised With JavaScript Compiler.

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.

yarn add @goa/append-field

Table Of Contents

API

The package is available by importing its default function:

import appendField from '@goa/append-field'

appendField(
  store: Object,
  key: string,
  value: string,
): void

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

import appendField from '@goa/append-field'

const obj = {}

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' } ] }

Copyright

Original Work by Linus Unnebäck.


Art Deco © Art Deco for Idio 2019 Idio Tech Nation Visa Tech Nation Visa Sucks