Form data support for Bare, implementing the FormData, Blob, and File APIs per the W3C File API and WHATWG multipart form data specifications.
npm i bare-form-data
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)To register FormData, Blob, and File as globals:
require('bare-form-data/global')Create a new FormData instance.
Append a new entry with the given name and value. If value is not a string and not a File, it will be wrapped in a File with the given filename or 'blob' as the default name.
Set the entry with the given name to value, replacing any existing entries with the same name.
Remove all entries with the given name.
Return the first value associated with name, or null if no entry exists.
Return an array of all values associated with name.
Return true if an entry with the given name exists.
Create a new Blob from an array of parts, which may be strings, Blob instances, buffers, or typed arrays.
Options include:
options = {
type
}The size of the blob in bytes.
The MIME type of the blob.
Return a ReadableStream that yields the blob contents.
Return the blob contents as a Buffer.
Return the blob contents as a Buffer.
Return the blob contents as an ArrayBuffer.
Return the blob contents as a UTF-8 string.
Test whether value is a Blob instance.
Create a new File from an array of parts with the given name. Extends Blob.
Options include:
options = {
type,
lastModified: Date.now()
}The name of the file.
The last modified timestamp of the file in milliseconds.
Test whether value is a File instance.
Test whether value is a FormData instance.
Encode a FormData instance as a Blob. The mimeType defaults to 'multipart/form-data' and is currently the only supported type.
Apache-2.0