0.0.40 • Published 3 years ago

@polyfiller/form-data v0.0.40

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

A robust polyfill for the 'FormData' interface

Description

This is a robust, feature complete polyfill for the FormData Web API that is accessible in Window or Worker contexts. It differs from existing implementations in that by default, it won't replace the existing FormData constructor in browsers that support a subset of the API, such as IE 10 and IE 11. This avoids having to patch other APIs such as fetch or XmlHttpRequest and makes it a seamless drop-in replacement.

Features

  • A seamless drop-in replacement.
  • Only patches whatever holes are missing if FormData is already supported.
  • Doesn't patch any other APIs.

Backers

BubblesTwitter: @usebubblesChristopher BlanchardIdeal PostcodesXerox

Patreon

Table of Contents

Install

npm

$ npm install @polyfiller/form-data

Yarn

$ yarn add @polyfiller/form-data

pnpm

$ pnpm add @polyfiller/form-data

Applying the polyfill

The polyfill will check if the browser already supports FormData and will only be applied if the runtime doesn't already support it.

To include it, add this somewhere in either a Window or Worker context:

import "@polyfiller/form-data/polyfill";

However, it is generally a good idea that you only include the polyfill for runtimes that don't already support FormData. One way to do so is with an async import:

if (typeof FormData === "undefined") {
	await import("@polyfiller/form-data/polyfill");
}

Alternatively, you can use Polyfill.app which uses this polyfill and takes care of only loading the polyfill if needed as well as adding the language features that the polyfill depends on (See dependencies).

Usage

This polyfill is a drop-in replacement, so you shouldn't have to update your code by any means.

Dependencies & Browser support

This polyfill is distributed in ES5-compatible syntax, and will add features such as Symbol.toStringTag and Symbol.iterator depending on the availability in the runtime. There are no hard dependencies below ES5.

Generally, I would highly recommend using something like Polyfill.app which takes care of this stuff automatically.

Maintainers

Frederik WessbergTwitter: @FredWessbergGithub: @wessbergLead Developer

FAQ

Are there any known quirks?

If you load this polyfill In IE <=9 where there is no FormData constructor, and you add one or more File objects as FormData, you will have to add some special handling for passing them as body to the request options when using XmlHttpRequest or a polyfilled version of the fetch Api, as these do not natively support FormData in these browsers.

License

MIT © Frederik Wessberg (@FredWessberg) (Website)