mirror of
https://github.com/denoland/deno.git
synced 2025-09-29 21:54:48 +00:00
fs utils getFileInfoType() return undefined when not found (denoland/deno_std#341)
Original: 0a61800163
This commit is contained in:
parent
bbdd51574c
commit
0fb83ba0d2
3 changed files with 20 additions and 20 deletions
24
fs/utils.ts
24
fs/utils.ts
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue