From e331aeca3e657d50119cf465c55550e425aafbe1 Mon Sep 17 00:00:00 2001 From: James Bronder <36022278+jbronder@users.noreply.github.com> Date: Tue, 7 Jan 2025 20:08:30 -0800 Subject: [PATCH] feat(fs/unstable): added DirEntry type and conversion function #6255 --- fs/_to_dir_entry.ts | 12 ++++++++++++ fs/unstable_types.ts | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 fs/_to_dir_entry.ts diff --git a/fs/_to_dir_entry.ts b/fs/_to_dir_entry.ts new file mode 100644 index 000000000000..7397e851f61c --- /dev/null +++ b/fs/_to_dir_entry.ts @@ -0,0 +1,12 @@ +// Copyright 2018-2025 the Deno authors. MIT license. + +import type { DirEntry } from "./unstable_types.ts"; + +export function toDirEntry(s: import("node:fs").Dirent): DirEntry { + return { + name: s.name, + isFile: s.isFile(), + isDirectory: s.isDirectory(), + isSymlink: s.isSymbolicLink(), + }; +} diff --git a/fs/unstable_types.ts b/fs/unstable_types.ts index 1f35e433cd0c..8f678dab7165 100644 --- a/fs/unstable_types.ts +++ b/fs/unstable_types.ts @@ -80,3 +80,18 @@ export interface FileInfo { * _Linux/Mac OS only._ */ isSocket: boolean | null; } + +export interface DirEntry { + /** The file name of the entry. It is just the entity name and does not + * include the full path. */ + name: string; + /** True if this is info for a regular file. Mutually exclusive to + * `FileInfo.isDirectory` and `FileInfo.isSymlink`. */ + isFile: boolean; + /** True if this is info for a regular directory. Mutually exclusive to + * `FileInfo.isFile` and `FileInfo.isSymlink`. */ + isDirectory: boolean; + /** True if this is info for a symlink. Mutually exclusive to + * `FileInfo.isFile` and `FileInfo.isDirectory`. */ + isSymlink: boolean; +}