@@ -14,21 +14,23 @@ import {FileLike} from "../FileLike.js"
14
14
* This function will return `true` for FileAPI compatible `File` objects:
15
15
*
16
16
* ```
17
- * import {isFileLike } from "form-data-encoder "
17
+ * import {createReadStream } from "node:fs "
18
18
*
19
- * isFileLike(new File(["Content"], "file.txt")) // -> true
19
+ * import {isFile} from "form-data-encoder"
20
+ *
21
+ * isFile(new File(["Content"], "file.txt")) // -> true
20
22
* ```
21
23
*
22
24
* However, if you pass a Node.js `Buffer` or `ReadStream`, it will return `false`:
23
25
*
24
26
* ```js
25
- * import {isFileLike } from "form-data-encoder"
27
+ * import {isFile } from "form-data-encoder"
26
28
*
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
29
31
* ```
30
32
*/
31
- export const isFileLike = ( value ?: unknown ) : value is FileLike => Boolean (
33
+ export const isFile = ( value ?: unknown ) : value is FileLike => Boolean (
32
34
( value as FileLike )
33
35
&& typeof ( value as FileLike ) === "object"
34
36
&& isFunction ( ( value as FileLike ) . constructor )
@@ -38,3 +40,35 @@ export const isFileLike = (value?: unknown): value is FileLike => Boolean(
38
40
&& ( value as FileLike ) . size != null
39
41
&& ( value as FileLike ) . lastModified != null
40
42
)
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
0 commit comments