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 - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

lib/object-to-form-data.cjs

90

package.json
{
"type": "module",
"name": "@octetstream/object-to-form-data",
"version": "2.0.0",
"version": "3.0.0",
"description": "Serialize given object/collection to a FormData.",
"repository": "octet-stream/object-to-form-data",
"repository": {
"type": "git",
"url": "git+https://github.com/octet-stream/object-to-form-data.git"
},
"author": "Nick K. <nick.kruchinin@gmail.com>",
"license": "MIT",
"main": "serialize.js",
"types": "serialize.d.ts",
"main": "./lib/object-to-form-data.js",
"types": "./lib/object-to-form-data.ts",
"exports": {
"import": {
"types": "./lib/object-to-form-data.ts",
"default": "./lib/object-to-form-data.js"
},
"require": {
"types": "./lib/object-to-form-data.cts",
"default": "./lib/object-to-form-data.cjs"
}
},
"files": [
"lib"
],
"engines": {
"node": ">= 12"
"node": ">= 18"
},
"browser": {
"./form-data": "./form-data-browser"
"devDependencies": {
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.1",
"@octetstream/eslint-config": "8.0.2",
"@size-limit/preset-small-lib": "11.0.2",
"@types/node": "20.11.17",
"@types/sinon": "17.0.3",
"ava": "6.1.1",
"c8": "9.1.0",
"eslint": "8.56.0",
"formdata-node": "6.0.3",
"husky": "9.0.11",
"lint-staged": "15.2.2",
"sinon": "17.0.1",
"size-limit": "11.0.2",
"tsup": "8.0.2",
"tsx": "4.7.1",
"typescript": "5.3.3"
},
"scripts": {
"limit": "size-limit",
"staged": "lint-staged",
"eslint": "eslint *.js",
"test": "ava",
"coverage": "c8 npm test",
"ci": "c8 npm test && c8 report --reporter=json",
"_postinstall": "husky install",
"prepublishOnly": "pinst --disable",
"postpublish": "pinst --enable"
},
"devDependencies": {
"@octetstream/eslint-config": "5.0.0",
"@size-limit/preset-small-lib": "4.10.2",
"ava": "3.15.0",
"c8": "7.7.2",
"eslint": "7.26.0",
"eslint-plugin-ava": "12.0.0",
"formdata-node": "3.3.2",
"husky": "6.0.0",
"lint-staged": "11.0.0",
"pinst": "^2.1.6",
"proxyquire": "2.1.3",
"size-limit": "4.10.2",
"typescript": "4.2.4"
},
"peerDependencies": {
"formdata-node": ">= 3.x"
},
"peerDependenciesMeta": {
"formdata-node": {
"optional": true
}
"build": "pnpm run lint:types && tsup",
"eslint": "eslint src/**/*.ts",
"lint:types": "tsc --noEmit",
"test": "NODE_OPTIONS=\"--no-warnings --import tsx\" ava",
"coverage": "c8 pnpm test",
"coverage:report": "c8 pnpm test && c8 report --reporter=html",
"ci": "c8 pnpm test && c8 report --reporter=json",
"release": "pnpm run build && pnpm exec changeset publish",
"preinstall": "npx only-allow pnpm"
}
}
}

@@ -10,17 +10,19 @@ # object-to-form-data

## API
## Installation
`serialize(object[, options]) -> {FormData}`
pnpm:
* **{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.
```sh
pnpm add @octetstream/object-to-form-data
```
npm:
```sh
npm i @octetstream/object-to-form-data
```
## Usage
```js
import serialize from "@octetstream/object-to-form-data"
import {objectToFormData} from "@octetstream/object-to-form-data"

@@ -40,7 +42,8 @@ const object = {

// You will receive a FormData instance with all fields of given object
const form = objectToFormData(object)
const options = {
method: "post",
// You will receive a FormData instance with all fields of given object
body: serialize(object)
body: form
}

@@ -51,2 +54,38 @@

**Important!** If you're using this library in Node.js, you also need the [formdata-node](https://github.com/octet-stream/form-data) package to serialize your objects/collections. See documentation of this implementation to learn how to send queries with that implementation.
## 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:
| Name | Type | Required | Default | Description |
|---------|:---------------------------------------------------------------:|:---------:|:-----------:|----------------------------------|
| input | `unknown[] \| Record<sting \| number, unknown>` | true | – | An object to transform |
| options | [`ObjectToFormDataOptions`](#interface-objecttoformdataoptions) | false | `undefined` | Additional serialization options |
### `interface ObjectToFormDataOptions`
Serialization options
| Name | Type | Required | Default | Description |
|----------------|:----------------------------------------:|:--------:|:---------------------:|---------------------------------------------------------------------------------------------------------------|
| strict | `boolean` | false | `false` | Indicates whether or not to omit every `false` values. Applied enabled. Does not affect boolean array values |
| FormData | `FormData` | false | `globalThis.FormData` | Custom spec-compliant [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) implementation |
| notation | `"dot" \| "bracket"` | false | `"bracket"` | Type of the path notation. Can be either `"dot"` or `"bracket"` |
| normalizeValue | [`NormalizeValue`](#type-normalizevalue) | false | `undefined` | Value 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:
| Name | Type | Description |
|---------|:-------------------------:|-------------------------------------|
| value | `unknown` | Current entry value |
| name | `string` | The name of the entry |
| path | `Array<string \| number>` | Entry's path within original object |
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