Bare Docs
ReferenceBareModules

bare-form-data

Reference for bare-form-data: WHATWG FormData, Blob, and File support for Bare, with a toBlob helper for multipart bodies.

stable

bare-form-data provides the WHATWG FormData, Blob, and File APIs for Bare, plus a toBlob helper to serialize a form into a multipart body. It's pure JavaScript and pairs with bare-fetch.

npm i bare-form-data

Usage

const { FormData, Blob, File, toBlob } = require('bare-form-data')

const form = new FormData()
form.append('title', 'Hello form')
form.append('attachment', new File(['My attachment'], 'attachment.txt', { type: 'text/plain' }))

const blob = toBlob(form)

Global registration

To register FormData, Blob, and File as globals across the entire application:

require('bare-form-data/global')

API

FormData

const formData = new FormData()

A multipart form where a name may hold more than one entry: append(name, value[, filename]) adds an entry, wrapping a non-string value in a File (named filename or, failing that, 'blob'; a value that's already a File is only rewrapped when filename is given); set(name, value[, filename]) removes any existing entries for name and appends this one in their place; delete(name) removes every entry for name; get(name) returns the first value for name, or null if there is none; getAll(name) returns every value for name; has(name) reports whether name has any entry.

const result = isFormData(value)

A module-level export. Returns true if value is a FormData instance.

const blob = toBlob(formData[, mimeType])

A module-level export. Serializes formData to a Blob. mimeType defaults to 'multipart/form-data', currently the only supported value — passing anything else throws INVALID_MIME_TYPE.

Blob

const blob = new Blob(parts[, options])

An immutable binary object built from parts (strings, Blob/File instances, buffers, or typed arrays) with an optional options.type: size, type, stream(), and the async readers buffer(), bytes(), arrayBuffer(), text(), plus Blob.isBlob(value).

File

const file = new File(parts, name[, options])

A Blob with a name and lastModified (options.lastModified defaults to Date.now()), plus File.isFile(value).

Builds on bare-buffer and bare-stream (see Bare modules).

See also

Last updated on

Was this helpful?

On this page