New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
increased by111.45%
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

Installation

pnpm:

pnpm add @octetstream/object-to-form-data

npm:

npm i @octetstream/object-to-form-data

Usage

import {objectToFormData} 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."
      }
    ]
  }
}

// You will receive a FormData instance with all fields of given object
const form = objectToFormData(object)

const options = {
  method: "post",
  body: form
}

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

API

objectToFormData(input[, options]): FormData

Indicates whether or not to omit every false values. Applied enabled. Does not affect boolean array values

This function takes following arguments:

NameTypeRequiredDefaultDescription
inputunknown[] | Record<sting | number, unknown>trueAn object to transform
optionsObjectToFormDataOptionsfalseundefinedAdditional serialization options

interface ObjectToFormDataOptions

Serialization options

NameTypeRequiredDefaultDescription
strictbooleanfalsefalseIndicates whether or not to omit every false values. Applied enabled. Does not affect boolean array values
FormDataFormDatafalseglobalThis.FormDataCustom spec-compliant FormData implementation
notation"dot" | "bracket"false"bracket"Type of the path notation. Can be either "dot" or "bracket"
normalizeValueNormalizeValuefalseundefinedValue normalizer. This function will be called on each scalar value, before it's added to FormData instance

type NormalizeValue

Value normalizer.

This function will be called on each scalar value, before it's added to FormData instance. It must return either Blob or string

This function will be called with the following arguments:

NameTypeDescription
valueunknownCurrent entry value
namestringThe name of the entry
pathArray<string | number>Entry's path within original object

FAQs

Package last updated on 14 Feb 2024

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