Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
append-field
Advanced tools
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.
The append-field npm package is designed to facilitate the manipulation of form data, specifically for appending fields to an existing FormData instance. It is particularly useful in scenarios where you need to dynamically add fields to FormData before submitting it, such as in file uploads or when dealing with complex form structures.
Appending fields to FormData
This feature allows you to append a new field to an existing FormData object. The code sample demonstrates how to append a simple key-value pair to FormData.
const appendField = require('append-field');
let formData = new FormData();
appendField(formData, 'key', 'value');
Appending nested fields to FormData
This feature enables appending nested fields to FormData, which is useful for representing complex data structures. The code sample shows how to append nested fields to represent a user's name and email.
const appendField = require('append-field');
let formData = new FormData();
appendField(formData, 'user[name]', 'John Doe');
appendField(formData, 'user[email]', 'john@example.com');
The form-data package is similar to append-field in that it is used to create and manipulate FormData objects. However, form-data provides a broader set of functionalities for handling FormData, including the ability to directly append files and streams, making it more suitable for file uploads.
Formidable is another package that deals with form data but from a different angle. It is primarily focused on parsing incoming form data, especially file uploads. While append-field is about appending data to FormData, formidable excels in extracting and processing data from incoming forms.
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
).
npm install --save append-field
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' } ] }
appendField(store, key, value)
Adds the field named key
with the value value
to the object store
.
MIT
FAQs
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.
The npm package append-field receives a total of 4,643,382 weekly downloads. As such, append-field popularity was classified as popular.
We found that append-field demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.