1.0.0 • Published 3 years ago

object-to-formdata-fix v1.0.0

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

object-to-formdata

Convenient JavaScript function that converts Objects to FormData instances.

npm npm

Install

npm install object-to-formdata

Usage

NOTE: STARTING WITH VERSION 3.0.0, THERE IS NO DEFAULT EXPORT!

import { objectToFormData } from 'object-to-formdata';

const object = {
  /**
   * key-value mapping
   * values can be primitives or objects
   */
};

const options = {
  /**
   * include array indices in FormData keys
   * defaults to false
   */
  indices: false,

  /**
   * treat null values like undefined values and ignore them
   * defaults to false
   */
  nullsAsUndefineds: false,

  /**
   * convert true or false to 1 or 0 respectively
   * defaults to false
   */
  booleansAsIntegers: false,
};

const formData = objectToFormData(
  object,
  options, // optional
  existingFormData, // optional
  keyPrefix, // optional
);

console.log(formData);