Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
octet-stream committed Feb 14, 2024
1 parent 61babf1 commit 2609444
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ root = true
end_of_line = lf
insert_final_newline = true

[*.{js,json,md,yml}]
[*.{ts,js,json,md,yml}]
charset = utf-8
indent_style = space
indent_size = 2
27 changes: 26 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const response = await fetch("https://httpbin.org/post", options)

## API

`objectToFormData(input[, options]): FormData`
### `objectToFormData(input[, options]): FormData`

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

Expand All @@ -61,3 +61,28 @@ This function takes following arguments:
|---------|:---------------------------------------------:|:---------:|:-----------:|----------------------------------|
| input | `unknown[] | Record<sting | number, unknown>` | true || An object to transform |
| options | `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` | false | undefined | Value normalizer. This function will be called on each *scalar* value, before it's added to FormData instance |

### `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 |
8 changes: 4 additions & 4 deletions src/objectToFormData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {Input} from "./Input.js"
*
* This function will be called on each *scalar* value, before it's added to FormData instanceю
*
* @param value - current entry value
* @param name - name of the entry
* @param path - entry's path within original object
* @param value - Current entry value
* @param name - The name of the entry
* @param path - Entry's path within original object
*/
export type NormalizeValue = (
value: unknown,
Expand Down Expand Up @@ -80,7 +80,7 @@ export interface ObjectToFormDataOptions {
/**
* Value normalizer.
*
* This function will be called on each *scalar* value, before it's added to FormData instanceю
* This function will be called on each *scalar* value, before it's added to FormData instance.
*/
normalizeValue?: NormalizeValue
}
Expand Down

0 comments on commit 2609444

Please sign in to comment.