JSPM

formdata-to-string

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3813
  • Score
    100M100P100Q10965F
  • License ISC

Transform a FormData object into a raw string

Package Exports

  • formdata-to-string
  • formdata-to-string/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (formdata-to-string) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

formdata-to-string

Transform a FormData instance into a raw string.

Build

Installation

npm install --save formdata-to-string

Usage

This library is built up of internal methods from within Node's internal fetch library, undici for transforming a FormData instance into something that can be supplied in a fetch request. The purpose of this is to silo the conversion and stream reading aspect of that process so that output can be used in other methods (eg. unit testing, code snippet generation, etc.).

import formDataToString from 'formdata-to-string';
// const { default: formDataToString } = require('formdata-to-string');

const form = new FormData();
form.append('dog', 'buster');
form.append('age', '18');

console.log(await formDataToString(form));
------formdata-undici-089527285518
Content-Disposition: form-data; name="dog"

buster
------formdata-undici-089527285518
Content-Disposition: form-data; name="age"

18
------formdata-undici-089527285518--

It also supports File and Blob objects that can be supplied to the FormData API:

const form = new FormData();

const dataURL = 'data:image/png;name=owlbert.png;base64,iVBORw0KGgo...';
form.append('image', new Blob([dataURL], { type: 'image/png' }), 'owlbert.png');

console.log(await formDataToString(form));
------formdata-undici-075655755345
Content-Disposition: form-data; name="image"; filename="owlbert.png"
Content-Type: image/png

data:image/png;name=owlbert.png;base64,iVBORw0KGgo...
------formdata-undici-075655755345--