Coder Social home page Coder Social logo

form-data-entries's Introduction

FormData.entries ponyfill

This ponyfill implements the FormData serialization algorithm. It aims to be compatible with calling the native new FormData(form).entries(). jQuery's serializeArray is another implementation example.

Usage

import formDataEntries from 'form-data-entries'

for (const [name, value] of formDataEntries(myForm)) {
  console.log(`${name}=${value}`)
}

Why ponyfill?

This package implements FormData.entries as a module ponyfill rather than a polyfill. FormData.entries was a later addition to the FormData specification. Therefore browsers may support FormData but not the entries method. It would be dangerous to attempt to fill just this additional entries method in browsers that have partial support. This module only implements entries as a standalone function which will even work in browsers with no FormData support.

However, once FormData.entries is widely supported this package should be considered obsolete.

Undefined Behavior

This module makes a best effort to match the behavior of native FormData.entries. It should be possible in the future to replace calls to formDataEntries(form) with new FormData(form).entries(). However, there are some cases where this module can not fully match the native behavior.

  • If the form contains any <input type=file> elements, the behavior is considered undefined and should not be relied upon.
  • In Safari when FormData is constructed on the submit event, it will include the submitter value. This behavior does not exist in other browsers, and is not and can not be implemented in the ponyfill since the submitter element is not exposed.

Test Suite

form-data-entries's People

Contributors

josh avatar keithamus avatar muan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

form-data-entries's Issues

Do not use native API

"Ponyfills should never use the native API, even if available, as it might have slightly different behavior between environments, which can cause bugs." [https://github.com/sindresorhus/ponyfill]

So, you can remove this from the ponyfill:

if (typeof FormData === 'function' && 'entries' in FormData.prototype) {
  formDataEntries = function(form) {
    return Array.from(new FormData(form).entries())
  }
} else {

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.