Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nested-formdata

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nested-formdata

This is a JavaScript utility function that converts JavaScript nested objects into FormData. It's beneficial when you need to send your data to the server in multipart/form-data format. This utility is built with TypeScript and Lodash.

  • 1.0.2
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Object to FormData Converter

This is a JavaScript utility function that converts JavaScript nested objects into FormData. It's beneficial when you need to send your data to the server in multipart/form-data format. This utility is built with TypeScript and Lodash.

Installation

To install this package, use the following command:

npm install nested-formdata

Usage

First, import the function into your JavaScript or TypeScript file:

import { objectToFormData } from 'nested-formdata';

You can then use the objectToFormData function to convert an objects or array of objects to FormData:

const data = {
  name: 'John Doe',
  age: 30,
  photo: File // This can be an instance of File Or array of Files
};

const formData = objectToFormData(data);

You can also handle nested objects:

const data = {
  name: 'John Doe',
  age: 30,
  address: {
    city: 'New York',
    state: 'NY'
    array: [1, 2, 3],
    image: File,
  }
};

const formData = objectToFormData(data);

API

objectToFormData(obj, form, namespace)

Parameters

  • obj (Object): The object to convert.
  • form (FormData, optional): Existing FormData to use.
  • namespace (String, optional): Namespace to prefix keys with.

Returns

  • (FormData): The resulting FormData object.

Contributing

Pull requests are welcome. Please make sure to update tests as appropriate.

License

This project is licensed under the MIT License.

Keywords

FAQs

Package last updated on 03 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc