-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve in-code documentation for utilities. Rename isFile.ts -> isFi…
…leLike.ts to match public API naming.
- Loading branch information
1 parent
1ed9fad
commit 71cfeff
Showing
11 changed files
with
80 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from "./FormDataEncoder" | ||
export * from "./FormDataLike" | ||
export * from "./FileLike" | ||
|
||
export {default as isFileLike} from "./util/isFile" | ||
export {default as isFormDataLike} from "./util/isFormData" | ||
// Utilities | ||
export * from "./FileLike" | ||
export * from "./FormDataLike" | ||
export * from "./util/isFileLike" | ||
export * from "./util/isFormData" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import isFunction from "./isFunction" | ||
|
||
import {FileLike} from "../FileLike" | ||
|
||
/** | ||
* Check if given object is `File`. | ||
* | ||
* Note that this function will return `false` for Blob, because the FormDataEncoder expects FormData to return File when a value is binary data. | ||
* | ||
* @param value an object to test | ||
* | ||
* @api public | ||
* | ||
* This function will return `true` for FileAPI compatible `File` objects: | ||
* | ||
* ``` | ||
* import {isFileLike} from "form-data-encoder" | ||
* | ||
* isFileLike(new File(["Content"], "file.txt")) // -> true | ||
* ``` | ||
* | ||
* However, if you pass a Node.js `Buffer` or `ReadStream`, it will return `false`: | ||
* | ||
* ```js | ||
* import {isFileLike} from "form-data-encoder" | ||
* | ||
* isFileLike(Buffer.from("Content")) // -> false | ||
* isFileLike(fs.createReadStream("path/to/a/file.txt")) // -> false | ||
* ``` | ||
*/ | ||
export const isFileLike = (value?: unknown): value is FileLike => Boolean( | ||
(value as FileLike) | ||
&& typeof (value as FileLike) === "object" | ||
&& isFunction((value as FileLike).constructor) | ||
&& (value as FileLike)[Symbol.toStringTag] === "File" | ||
&& isFunction((value as FileLike).stream) | ||
&& (value as FileLike).name != null | ||
&& (value as FileLike).size != null | ||
&& (value as FileLike).lastModified != null | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters