Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 838 Bytes

readme.md

File metadata and controls

45 lines (34 loc) · 838 Bytes

toFormData

A small javascript utility for converting to form data

npm

Install

npm install @ankit_brahmbhatt/toFormData

Usage

import { toFormData } from "@ankit_brahmbhatt/toformdata";

const object = {
  /**
   * key-value mapping
   */
};

const options = {
  /**
   * Remove null and undefined values from formData object
   */
  removeNullAndUndefined: false,

  /**
   * Use bracket format instead of dot format for js objects . Defaults to false
   */
  useBracketsForObjects: false,
};

const formData = toFormData(
  object,
  options // optional
);

// log formdata to the console
for (let value of formData.entries()) {
  console.log(value[0] + ", " + value[1]);
}