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

@octetstream/object-to-form-data

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octetstream/object-to-form-data

Serialize given object/collection to a FormData.

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
949
decreased by-21.96%
Maintainers
1
Weekly downloads
 
Created
Source

object-to-form-data

Transform an object/collection to FormData. Good to use with then-busboy

Code Coverage CI ESLint

API

serialize(object[, options]) -> {FormData}

  • {object} object – Object to transform
  • {object | boolean} options – Serialization options. This argument might be an object with "root" and "strict" parameters. Or you can pass one of them as the second argument:
    • {boolean} [strict = false] – if set to true, all false boolean values will be omitted.

Usage

import serialize from "@octetstream/object-to-form-data"

const object = {
  message: {
    sender: "Glim Glam",
    text: "Can you believe it, Trixie?",
    attachments: [
      {
        file: File, // this field will be represented as a window.File instance
        description: "I beat Twilight Sparkle and all I got was this lousy t-shirt."
      }
    ]
  }
}

const options = {
  method: "post",

  // You will receive a FormData instance with all fields of given object
  body: serialize(object)
}

const response = await fetch("https://httpbin.org/post", options)

Important! If you're using this library in Node.js, you also need the formdata-node package to serialize your objects/collections. See documentation of this implementation to learn how to send queries with that implementation.

FAQs

Package last updated on 16 May 2021

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