Skip to content

Commit 38ec5b3

Browse files
committed
Remove depreacated isFormDataLike and deprecate isFileLike in favour of isFile
1 parent 3547a32 commit 38ec5b3

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

src/util/isFileLike.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,23 @@ import {FileLike} from "../FileLike.js"
1414
* This function will return `true` for FileAPI compatible `File` objects:
1515
*
1616
* ```
17-
* import {isFileLike} from "form-data-encoder"
17+
* import {createReadStream} from "node:fs"
1818
*
19-
* isFileLike(new File(["Content"], "file.txt")) // -> true
19+
* import {isFile} from "form-data-encoder"
20+
*
21+
* isFile(new File(["Content"], "file.txt")) // -> true
2022
* ```
2123
*
2224
* However, if you pass a Node.js `Buffer` or `ReadStream`, it will return `false`:
2325
*
2426
* ```js
25-
* import {isFileLike} from "form-data-encoder"
27+
* import {isFile} from "form-data-encoder"
2628
*
27-
* isFileLike(Buffer.from("Content")) // -> false
28-
* isFileLike(fs.createReadStream("path/to/a/file.txt")) // -> false
29+
* isFile(Buffer.from("Content")) // -> false
30+
* isFile(createReadStream("path/to/a/file.txt")) // -> false
2931
* ```
3032
*/
31-
export const isFileLike = (value?: unknown): value is FileLike => Boolean(
33+
export const isFile = (value?: unknown): value is FileLike => Boolean(
3234
(value as FileLike)
3335
&& typeof (value as FileLike) === "object"
3436
&& isFunction((value as FileLike).constructor)
@@ -38,3 +40,35 @@ export const isFileLike = (value?: unknown): value is FileLike => Boolean(
3840
&& (value as FileLike).size != null
3941
&& (value as FileLike).lastModified != null
4042
)
43+
44+
/**
45+
* Check if given object is `File`.
46+
*
47+
* Note that this function will return `false` for Blob, because the FormDataEncoder expects FormData to return File when a value is binary data.
48+
*
49+
* @param value an object to test
50+
*
51+
* @api public
52+
*
53+
* @deprecated use `isFile` instead
54+
*
55+
* This function will return `true` for FileAPI compatible `File` objects:
56+
*
57+
* ```
58+
* import {isFileLike} from "form-data-encoder"
59+
*
60+
* isFileLike(new File(["Content"], "file.txt")) // -> true
61+
* ```
62+
*
63+
* However, if you pass a Node.js `Buffer` or `ReadStream`, it will return `false`:
64+
*
65+
* ```js
66+
* import {createReadStream} from "node:fs"
67+
*
68+
* import {isFileLike} from "form-data-encoder"
69+
*
70+
* isFileLike(Buffer.from("Content")) // -> false
71+
* isFileLike(createReadStream("path/to/a/file.txt")) // -> false
72+
* ```
73+
*/
74+
export const isFileLike = isFile

src/util/isFormData.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,3 @@ export const isFormData = (value?: unknown): value is FormDataLike => Boolean(
1616
&& isFunction((value as FormDataLike).entries)
1717
&& isFunction((value as FormDataLike)[Symbol.iterator])
1818
)
19-
20-
/**
21-
* Check if given object is FormData
22-
*
23-
* @param value an object to test
24-
*
25-
* @deprecated use `isFormData` instead.
26-
*/
27-
export const isFormDataLike = isFormData

0 commit comments

Comments
 (0)