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 3.0.2 to 3.0.3

43

lib/object-to-form-data.d.ts

@@ -13,13 +13,22 @@ type PathEntry = string | number;

/**
* Value normalizer.
* Value normalizer callback
*
* This function will be called on each *scalar* value, before it's added to FormData instanceю
*
* @param value - Current entry value
* @param name - The name of the entry
* @param path - Entry's path within original object
* @public
*/
type NormalizeValue = (value: unknown, name: string, path: Path) => string | Blob;
interface NormalizeValue {
/**
* Value normalizer callback.
*
* This function will be called on each *scalar* value, before it's added to FormData instanceю
*
* @param value - Current entry value
* @param name - The name of the entry
* @param path - Entry's path within original object
*/
(value: unknown, name: string, path: Path): string | Blob;
}
/**
* Serialization options
*
* @public
*/

@@ -74,3 +83,3 @@ interface ObjectToFormDataOptions {

/**
* Type of the path notation. Can be either `"dot"` or `"bracket"`
* Type of the nested fields notation. Can be either `"dot"` or `"bracket"`
*

@@ -87,5 +96,10 @@ * @default "bracket"

}
/**
* Transforms given object, array, or collection to FormData object
*
* @public
*/
interface ObjectToFormData {
/**
* Transform given object, array, or collection to FormData object
* Transforms given object, array, or collection to FormData object
*

@@ -96,3 +110,3 @@ * @param input - An object to transform

/**
* Transform given object, array, or collection to FormData object
* Transforms given object, array, or collection to FormData object
*

@@ -104,3 +118,3 @@ * @param input - An object to transform

/**
* Transform given object, array, or collection to FormData object
* Transforms given object, array, or collection to FormData object
*

@@ -112,3 +126,3 @@ * @param input - An object to transform

/**
* Transform given object, array, or collection to FormData object.
* Transforms given object, array, or collection to FormData object.
*

@@ -121,2 +135,7 @@ * **This method always enables `strict` option.**

}
/**
* Transforms given object, array, or collection to FormData object
*
* @public
*/
declare const objectToFormData: ObjectToFormData;

@@ -123,0 +142,0 @@ /**

@@ -44,4 +44,3 @@ // src/utils/pathToString.ts

function* createRecursiveIterator(input, path, strict) {
const entries = createEntriesIterator(input);
for (const [key, value] of entries) {
for (const [key, value] of createEntriesIterator(input)) {
const nextPath = [...path, key];

@@ -48,0 +47,0 @@ if (Array.isArray(value) || isPlainObject(value)) {

{
"type": "module",
"name": "@octetstream/object-to-form-data",
"version": "3.0.2",
"version": "3.0.3",
"description": "Serialize objects, arrays and collections into FormData.",

@@ -6,0 +6,0 @@ "keywords": [

@@ -65,4 +65,4 @@ # object-to-form-data

url = "https://github.com/octocat"
repositories[nodes][0][name] = Hello-World
repositories[nodes][0][description] = My first repository on GitHub!
repositories[nodes][0][name] = "Hello-World"
repositories[nodes][0][description] = "My first repository on GitHub!"
repositories[nodes][0][url] = "https://github.com/octocat/Hello-World"

@@ -159,2 +159,30 @@ ```

5. Serializing files and blobs:
```ts
import {objectToFormData} from "@octetstream/object-to-form-data"
const input = [
{
caption: "Text file created with File object",
file: new File(["My hovercraft if full of eels"], "test.txt", {type: "text/plain"}),
},
{
caption: "Text data created with Blob object",
file: new Blob(["On Soviet Moon landscape see binoculars through you"], {type: "text/plain"}),
}
]
const form = objectToFormData(input)
```
Result:
```
[0][caption] = "Text file created with File object"
[0][file] = File [type: "text/plain", name: "test.txt", content: "My hovercraft if full of eels"]
[1][caption] = "Text data created with Blob object"
[1][file] = File [type: "text/plain", name: "blob", content: "On Soviet Moon landscape see binoculars through you"]
```
## API

@@ -185,3 +213,3 @@

| 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"` |
| notation | `"dot" \| "bracket"` | false | `"bracket"` | Type of the nested fields 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 |

@@ -188,0 +216,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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