-
Notifications
You must be signed in to change notification settings - Fork 774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: .isFile()/.isDir()/.isLink()/.isSymlink() #998
Comments
I'm not completely closed to this idea. However, here's a couple of arguments against it:
|
Thanks for the quick response, I hadn't thought about this obfuscation! I was thinking primarily of One possible way to help make the end result more explicit could potentially be a boolean Another option I could see is to create a const ft = await fse.getType(path);
// {
// type: 'file' | 'dir' | null,
// isLink: true | false
// }
if (ft.type === 'dir') {
// Handle directory
else if (ft.type === 'file') {
// Handle file
if (ft.isLink) {
// Handle symlink to file
} else {
// Handle non-symlink file
}
} else if (ft.type === null) {
// Path doesn't exist!
} WDYT? |
Generally speaking, unnamed boolean options aren't a good idea. If we have a named option, that results in a function call that is longer than the vanilla function call: await fse.isFile(path, { symlinkAllowed: false })
(await fs.stat(path)).isFile()
Generally speaking, this is an anti-pattern. The Node.js docs state:
How is |
In mdn/yari, we use the following code to check to see if a file path is a directory:
It would be awesome for
fs-extra
to have a shortcut:The text was updated successfully, but these errors were encountered: