Giter VIP home page Giter VIP logo

formdata's Introduction

FormData

Greenkeeper badge

Build Status

npm version

JavaScript Style Guide

npm install formdata-polyfill

A FormData polyfill

This polyfill conditionally replaces the native implementation rather then fixing the missing functions, since otherwise there is no way to get or delete existing values in the FormData object. Therefore this also patches XMLHttpRequest.prototype.send and fetch to send the FormData as a blob, and navigator.sendBeacon to send native FormData.

I was unable to patch the Response/Request constructor so if you are constructing them with FormData you need to call fd._blob() manually.

new Request(url, {
  method: 'post',
  body: fd._blob ? fd._blob() : fd
})

Dependencies

If you need to support IE <= 9 then I recommend you to include eligrey's blob.js

Updating from 2.x to 3.x

Previously you had to import the polyfill and use that, since it didn't replace the global (existing) FormData implementation. But now it transparently calls _blob() for you when you are sending something with fetch or XHR, by way of monkey-patching the XMLHttpRequest.prototype.send and fetch functions.

So you maybe had something like this:

var FormData = require('formdata-polyfill')
var fd = new FormData(form)
xhr.send(fd._blob())

There is no longer anything exported from the module (though you of course still need to import it to install the polyfill), so you can now use the FormData object as normal:

require('formdata-polyfill')
var fd = new FormData(form)
xhr.send(fd)

The status of the native FormData (2018-11-15) is: skarmavbild 2018-11-15 kl 20 16 36

This polyfill normalizes support for the FormData API:

  • append with filename
  • delete(), get(), getAll(), has(), set()
  • entries(), keys(), values(), and support for for...of
  • Available in web workers (just include the polyfill)

formdata's People

Contributors

jimmywarting avatar greenkeeper[bot] avatar tremby avatar marlun78 avatar adamscybot avatar anddoutoi avatar ctjhoa avatar d11wtq avatar erikwiffin avatar glebm avatar visualjerk avatar mr-squirrel avatar

Watchers

James Cloos avatar irving avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.