Skip to content

Interface: NVEDirent

A reactive, browser-friendly implementation of Node.js Dirent for use with NVEFileSystem.

This class mimics the Node.js Dirent API, allowing you to represent files and directories in a virtual file system. All type-checking methods except isFile() return false by default.

The path property is provided for compatibility, but is deprecated in favor of using name and parentPath directly.

Example

ts
const file = new NVEDirent({ name: "App.vue", parentPath: "/src" });
file.isFile(); // true
file.path; // '/src/App.vue'

Extends

Extended by

Properties

PropertyModifierTypeDescriptionInherited from
namereadonlystringThe file name that this dirent represents, including the extension if applicable.Dirent.name
parentPathreadonlystringThe parent directory path of this dirent.Dirent.parentPath

Accessors

content

Get Signature

ts
get content(): string;

The file contents as a string. Setting this will update the Monaco model if present. Throws CannotAccessDisposedDirectException if the entry is disposed.

Returns

string

Set Signature

ts
set content(value: string): void;
Parameters
ParameterType
valuestring
Returns

void


dirty

Get Signature

ts
get dirty(): boolean;
Returns

boolean


extension

Get Signature

ts
get extension(): string | undefined;

Returns the file extension (without the dot) if this is a file, otherwise undefined. Throws CannotAccessDisposedDirectException if the entry is disposed.

Returns

string | undefined


icon

Get Signature

ts
get icon(): string;

Returns the icon URL for this entry based on its type and name. If this is a directory, it uses the folder icon; otherwise, it uses the file icon. Throws CannotAccessDisposedDirectException if the entry is disposed.

Returns

string


iconDark

Get Signature

ts
get iconDark(): string;

Returns the icon URL for this entry based on its type and name. If this is a directory, it uses the folder icon; otherwise, it uses the file icon. Throws CannotAccessDisposedDirectException if the entry is disposed.

Returns

string


iconDarkOpened

Get Signature

ts
get iconDarkOpened(): string;

Returns the icon URL for this entry when it is in an "opened" state. This is typically used for directories to indicate they are expanded. Throws CannotAccessDisposedDirectException if the entry is disposed.

Returns

string


iconOpened

Get Signature

ts
get iconOpened(): string;

Returns the icon URL for this entry when it is in an "opened" state. This is typically used for directories to indicate they are expanded. Throws CannotAccessDisposedDirectException if the entry is disposed.

Returns

string


isDisposed

Get Signature

ts
get isDisposed(): boolean;

Returns true if this entry has been disposed and is no longer usable.

Returns

boolean


language

Get Signature

ts
get language(): NVEDirentLanguage | undefined;

Returns the Monaco language identifier inferred from the file extension, if this is a file. Throws CannotAccessDisposedDirectException if the entry is disposed.

Returns

NVEDirentLanguage | undefined


lastModified

Get Signature

ts
get lastModified(): Date;

Returns the last modified date of this entry Throws CannotAccessDisposedDirectException if the entry is disposed.

Returns

Date


path

Get Signature

ts
get path(): string;

The full path of the entry, computed from parentPath and name.

Deprecated

Use name and parentPath instead for clarity and consistency.

Returns

string


uri

Get Signature

ts
get uri(): Uri;

Returns the Monaco Editor Uri for this file, creating and caching it if necessary. Throws CannotAccessDisposedDirectException if the entry is disposed.

Returns

Uri


virtual

Get Signature

ts
get virtual(): boolean;

Indicates that this dirent entry is virtual.

Returns

boolean

Methods

asModel()

ts
asModel(editor: typeof editor): ITextModel;

Returns the Monaco Editor ITextModel for this file, creating it if necessary. The model is kept in sync with the file's content and is disposed automatically. Throws CannotAccessDisposedDirectException if the entry is disposed.

Parameters

ParameterTypeDescription
editortypeof editorThe Monaco editor module to use for model creation.

Returns

ITextModel

The Monaco ITextModel instance for this file.


commit()

ts
commit(): Promise<boolean>;

Commits (saves) the current file using the provided commit handler.

This method invokes the user-provided NVECommitDirent hook (if defined) to persist changes. If the commit succeeds, returns true; otherwise, emits a commitError event and returns false.

Returns

Promise<boolean>

A Promise resolving to true if the commit succeeded, or false if it failed.

Throws

If the dirent is disposed.

Throws

If no commit handler is defined.

Example

ts
const file = new NVEDirent({ name: 'foo.txt', parentPath: '/', onCommit: async (d) => { ... } })
await file.commit()

dispose()

ts
dispose(): void;

Disposes of this entry, cleaning up all resources and notifying listeners. Emits the disposed event and throws on further access.

Returns

void


isBlockDevice()

ts
isBlockDevice(): boolean;

Returns true if the fs.Dirent object describes a block device.

Returns

boolean

Since

v10.10.0

Inherited from

Dirent.isBlockDevice


isCharacterDevice()

ts
isCharacterDevice(): boolean;

Returns true if the fs.Dirent object describes a character device.

Returns

boolean

Since

v10.10.0

Inherited from

Dirent.isCharacterDevice


isDirectory()

ts
isDirectory(): boolean;

Returns true if the fs.Dirent object describes a file system directory.

Returns

boolean

Since

v10.10.0

Inherited from

Dirent.isDirectory


isFIFO()

ts
isFIFO(): boolean;

Returns true if the fs.Dirent object describes a first-in-first-out (FIFO) pipe.

Returns

boolean

Since

v10.10.0

Inherited from

Dirent.isFIFO


isFile()

ts
isFile(): boolean;

Returns true if the fs.Dirent object describes a regular file.

Returns

boolean

Since

v10.10.0

Inherited from

Dirent.isFile


isSocket()

ts
isSocket(): boolean;

Returns true if the fs.Dirent object describes a socket.

Returns

boolean

Since

v10.10.0

Inherited from

Dirent.isSocket


ts
isSymbolicLink(): boolean;

Returns true if the fs.Dirent object describes a symbolic link.

Returns

boolean

Since

v10.10.0

Inherited from

Dirent.isSymbolicLink


isVirtual()

ts
isVirtual(): boolean;

Indicates that this dirent entry is virtual.

Returns

boolean

Always returns false for real entries.


offCommitError()

ts
offCommitError(callback: (error: unknown, dirent: NVEDirent) => void): void;

Removes a previously registered commit error callback.

Parameters

ParameterTypeDescription
callback(error: unknown, dirent: NVEDirent) => voidThe function to remove from the commitError event listeners.

Returns

void

Example

ts
const handler = (err, dirent) => { ... }
file.onCommitError(handler)
// ...
file.offCommitError(handler)

onceCommitError()

ts
onceCommitError(callback: (error: unknown, dirent: NVEDirent) => void): void;

Registers a callback to be invoked only once when a commit operation fails.

The callback will be called the next time a commitError event is emitted, then automatically removed.

Parameters

ParameterTypeDescription
callback(error: unknown, dirent: NVEDirent) => voidThe function to call on the next commit error. Receives the error and the dirent instance.

Returns

void

Example

ts
file.onceCommitError((err, dirent) => {
  alert("First commit failure!");
});

onCommitError()

ts
onCommitError(callback: (error: unknown, dirent: NVEDirent) => void): void;

Registers a callback to be invoked when a commit operation fails.

The callback will be called every time a commitError event is emitted (i.e., when the commit handler throws or rejects).

Parameters

ParameterTypeDescription
callback(error: unknown, dirent: NVEDirent) => voidThe function to call on commit error. Receives the error and the dirent instance.

Returns

void

Example

ts
file.onCommitError((err, dirent) => {
  console.error("Commit failed:", err);
});

onWillDispose()

ts
onWillDispose(callback: (dirent: NVEDirent) => void): void;

Registers a callback to be invoked when this entry is disposed. The callback is only called once.

Parameters

ParameterTypeDescription
callback(dirent: NVEDirent) => voidThe function to call when disposed.

Returns

void


toSerialized()

ts
toSerialized(): Promise<string>;

Serializes this NVEDirent instance to a compact, base64-encoded string.

The output includes the name, parentPath, content, and lastModified fields, and is prefixed for identification. This is suitable for storage, sharing, or persistence of file system state.

Returns

Promise<string>

A base64-encoded string representing the serialized dirent.