object-to-formdata
    TypeScript icon, indicating that this package has built-in type declarations

    4.1.0 • Public • Published

    object-to-formdata

    Convenient JavaScript function that serializes Objects to FormData instances.

    npm npm

    Install

    npm install object-to-formdata

    Usage

    NOTE: STARTING WITH VERSION 4.0.0, THE NAMED EXPORT HAS CHANGED!

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

    import { serialize } 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,
     
      /**
       * store arrays even if they're empty
       * defaults to false
       */
      allowEmptyArrays: false,
    };
     
    const formData = serialize(
      object,
      options, // optional
      existingFormData, // optional
      keyPrefix, // optional
    );
     
    console.log(formData);

    Install

    npm i object-to-formdata

    DownloadsWeekly Downloads

    35,572

    Version

    4.1.0

    License

    MIT

    Unpacked Size

    18.5 kB

    Total Files

    9

    Last publish

    Collaborators

    • therealparmesh