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

object-to-formdata

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-to-formdata

> Convenient JavaScript function that serializes Objects to FormData instances.

  • 4.5.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is object-to-formdata?

The object-to-formdata npm package is a utility that converts JavaScript objects into FormData instances. This is particularly useful for sending data via HTTP requests, especially when dealing with file uploads or complex nested objects.

What are object-to-formdata's main functionalities?

Basic Object to FormData Conversion

This feature allows you to convert a simple JavaScript object into a FormData instance. The code sample demonstrates converting an object with basic key-value pairs into FormData.

const objectToFormData = require('object-to-formdata');
const obj = { name: 'John', age: 30 };
const formData = objectToFormData(obj);
console.log([...formData.entries()]);

Nested Object Conversion

This feature supports converting nested objects into FormData. The code sample shows how a nested object structure is handled and converted.

const objectToFormData = require('object-to-formdata');
const obj = { user: { name: 'John', age: 30 }, active: true };
const formData = objectToFormData(obj);
console.log([...formData.entries()]);

Array Handling

This feature allows arrays within objects to be converted into FormData. The code sample demonstrates converting an object containing an array into FormData.

const objectToFormData = require('object-to-formdata');
const obj = { tags: ['node', 'javascript', 'npm'] };
const formData = objectToFormData(obj);
console.log([...formData.entries()]);

File Uploads

This feature supports file uploads by converting file streams into FormData. The code sample shows how to include a file in the object and convert it into FormData.

const objectToFormData = require('object-to-formdata');
const fs = require('fs');
const obj = { file: fs.createReadStream('path/to/file.txt') };
const formData = objectToFormData(obj);
console.log([...formData.entries()]);

Other packages similar to object-to-formdata

Keywords

FAQs

Package last updated on 12 May 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