Skip to content

Commit 18d2d61

Browse files
committed
Improve in code documentation examples.
1 parent 5ce8e84 commit 18d2d61

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

lib/FormDataEncoder.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,30 @@ export class FormDataEncoder {
8484
*
8585
* @example
8686
*
87-
* import {Encoder} from "form-data-encoder"
88-
* import {FormData} from "formdata-node"
87+
* import {Readable} from "stream"
88+
*
89+
* import {FormData, File, fileFromPath} from "formdata-node"
90+
* import {FormDataEncoder} from "form-data-encoder"
91+
*
92+
* import fetch from "node-fetch"
93+
*
94+
* const form = new FormData()
95+
*
96+
* form.set("field", "Just a random string")
97+
* form.set("file", new File(["Using files is class amazing"]))
98+
* form.set("fileFromPath", await fileFromPath("path/to/a/file.txt"))
8999
*
90-
* const fd = new FormData()
100+
* const encoder = new FormDataEncoder(form)
91101
*
92-
* fd.set("greeting", "Hello, World!")
102+
* const options = {
103+
* method: "post",
104+
* headers: encoder.headers,
105+
* body: Readable.from(encoder)
106+
* }
93107
*
94-
* const encoder = new Encoder(fd)
108+
* const response = await fetch("https://httpbin.org/post", options)
109+
*
110+
* console.log(await response.json())
95111
*/
96112
constructor(form: FormDataLike)
97113
constructor(form: FormDataLike, boundary: string)
@@ -212,7 +228,7 @@ export class FormDataEncoder {
212228
*
213229
* import {Readable} from "stream"
214230
*
215-
* import {Encoder} from "form-data-encoder"
231+
* import {FormDataEncoder} from "form-data-encoder"
216232
*
217233
* import {FormData} from "formdata-polyfill/esm-min.js"
218234
* import {fileFrom} from "fetch-blob/form.js"
@@ -221,13 +237,13 @@ export class FormDataEncoder {
221237
*
222238
* import fetch from "node-fetch"
223239
*
224-
* const fd = new FormData()
240+
* const form = new FormData()
225241
*
226-
* fd.set("field", "Just a random string")
227-
* fd.set("file", new File(["Using files is class amazing"]))
228-
* fd.set("fileFromPath", await fileFrom("path/to/a/file.txt"))
242+
* form.set("field", "Just a random string")
243+
* form.set("file", new File(["Using files is class amazing"]))
244+
* form.set("fileFromPath", await fileFrom("path/to/a/file.txt"))
229245
*
230-
* const encoder = new Encoder(fd)
246+
* const encoder = new FormDataEncoder(form)
231247
*
232248
* const options = {
233249
* method: "post",
@@ -261,17 +277,17 @@ export class FormDataEncoder {
261277
* import {Readable} from "stream"
262278
*
263279
* import {FormData, File, fileFromPath} from "formdata-node"
264-
* import {Encoder} from "form-data-encoder"
280+
* import {FormDataEncoder} from "form-data-encoder"
265281
*
266282
* import fetch from "node-fetch"
267283
*
268-
* const fd = new FormData()
284+
* const form = new FormData()
269285
*
270-
* fd.set("field", "Just a random string")
271-
* fd.set("file", new File(["Using files is class amazing"]))
272-
* fd.set("fileFromPath", await fileFromPath("path/to/a/file.txt"))
286+
* form.set("field", "Just a random string")
287+
* form.set("file", new File(["Using files is class amazing"]))
288+
* form.set("fileFromPath", await fileFromPath("path/to/a/file.txt"))
273289
*
274-
* const encoder = new Encoder(fd)
290+
* const encoder = new FormDataEncoder(form)
275291
*
276292
* const options = {
277293
* method: "post",

0 commit comments

Comments
 (0)