fs utils getFileInfoType() return undefined when not found (denoland/deno_std#341)

Original: 0a61800163
This commit is contained in:
Axetroy 2019-04-24 05:42:02 +08:00 committed by Ryan Dahl
parent bbdd51574c
commit 0fb83ba0d2
3 changed files with 20 additions and 20 deletions

View file

@ -17,24 +17,24 @@ export function isSubdir(
const srcArray = src.split(sep);
const destArray = dest.split(sep);
return srcArray.reduce((acc, current, i) => {
return srcArray.reduce((acc: boolean, current, i) => {
return acc && destArray[i] === current;
}, true);
}
export enum PathType {
file = "file",
dir = "dir",
symlink = "symlink"
}
export type PathType = "file" | "dir" | "symlink";
/* Get a human readable file type string */
export function getFileInfoType(fileInfo: Deno.FileInfo): PathType | null {
/**
* Get a human readable file type string.
*
* @param fileInfo A FileInfo describes a file and is returned by `stat`, `lstat`
*/
export function getFileInfoType(fileInfo: Deno.FileInfo): PathType {
return fileInfo.isFile()
? PathType.file
? "file"
: fileInfo.isDirectory()
? PathType.dir
? "dir"
: fileInfo.isSymlink()
? PathType.symlink
: null;
? "symlink"
: undefined;
}