Skip to content

Commit b5b2850

Browse files
committed
Improve documentation for FormDataLike interface.
1 parent 08b1023 commit b5b2850

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

lib/FormDataLike.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
import {FileLike} from "./FileLike"
22

33
/**
4-
* This interface reflects possible values of each FormData entry
4+
* A `string` or `File` that represents a single value from a set of `FormData` key-value pairs.
55
*/
66
export type FormDataEntryValue = string | FileLike
77

88
/**
99
* This interface reflects minimal shape of the FormData
1010
*/
1111
export interface FormDataLike {
12-
append(name: string, value: unknown, filename?: string): void
12+
/**
13+
* Appends a new value onto an existing key inside a FormData object,
14+
* or adds the key if it does not already exist.
15+
*
16+
* The difference between `set()` and `append()` is that if the specified key already exists, `set()` will overwrite all existing values with the new one, whereas `append()` will append the new value onto the end of the existing set of values.
17+
*
18+
* @param name The name of the field whose data is contained in `value`.
19+
* @param value The field's value. This can be [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
20+
or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
21+
* @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
22+
*/
23+
append(name: string, value: unknown, fileName?: string): void
1324

25+
/**
26+
* Returns all the values associated with a given key from within a `FormData` object.
27+
*
28+
* @param {string} name A name of the value you want to retrieve.
29+
*
30+
* @returns An array of `FormDataEntryValue` whose key matches the value passed in the `name` parameter. If the key doesn't exist, the method returns an empty list.
31+
*/
1432
getAll(name: string): FormDataEntryValue[]
1533

34+
/**
35+
* Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through the `FormData` key/value pairs.
36+
* The key of each pair is a string; the value is a [`FormDataValue`](https://developer.mozilla.org/en-US/docs/Web/API/FormDataEntryValue).
37+
*/
1638
entries(): Generator<[string, FormDataEntryValue]>
1739

40+
/**
41+
* An alias for FormDataLike#entries()
42+
*/
1843
[Symbol.iterator](): Generator<[string, FormDataEntryValue]>
1944

2045
[Symbol.toStringTag]: string

0 commit comments

Comments
 (0)