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
const file = new NVEDirent({ name: "App.vue", parentPath: "/src" });
file.isFile(); // true
file.path; // '/src/App.vue'Extends
Extended by
Properties
| Property | Modifier | Type | Description | Inherited from |
|---|---|---|---|---|
name | readonly | string | The file name that this dirent represents, including the extension if applicable. | Dirent.name |
parentPath | readonly | string | The parent directory path of this dirent. | Dirent.parentPath |
Accessors
content
Get Signature
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
set content(value: string): void;Parameters
| Parameter | Type |
|---|---|
value | string |
Returns
void
dirty
Get Signature
get dirty(): boolean;Returns
boolean
extension
Get Signature
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
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
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
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
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
get isDisposed(): boolean;Returns true if this entry has been disposed and is no longer usable.
Returns
boolean
language
Get Signature
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
get lastModified(): Date;Returns the last modified date of this entry Throws CannotAccessDisposedDirectException if the entry is disposed.
Returns
Date
path
Get Signature
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
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
get virtual(): boolean;Indicates that this dirent entry is virtual.
Returns
boolean
Methods
asModel()
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
| Parameter | Type | Description |
|---|---|---|
editor | typeof editor | The Monaco editor module to use for model creation. |
Returns
ITextModel
The Monaco ITextModel instance for this file.
commit()
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
const file = new NVEDirent({ name: 'foo.txt', parentPath: '/', onCommit: async (d) => { ... } })
await file.commit()dispose()
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()
isBlockDevice(): boolean;Returns true if the fs.Dirent object describes a block device.
Returns
boolean
Since
v10.10.0
Inherited from
isCharacterDevice()
isCharacterDevice(): boolean;Returns true if the fs.Dirent object describes a character device.
Returns
boolean
Since
v10.10.0
Inherited from
isDirectory()
isDirectory(): boolean;Returns true if the fs.Dirent object describes a file system directory.
Returns
boolean
Since
v10.10.0
Inherited from
isFIFO()
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
isFile()
isFile(): boolean;Returns true if the fs.Dirent object describes a regular file.
Returns
boolean
Since
v10.10.0
Inherited from
isSocket()
isSocket(): boolean;Returns true if the fs.Dirent object describes a socket.
Returns
boolean
Since
v10.10.0
Inherited from
isSymbolicLink()
isSymbolicLink(): boolean;Returns true if the fs.Dirent object describes a symbolic link.
Returns
boolean
Since
v10.10.0
Inherited from
isVirtual()
isVirtual(): boolean;Indicates that this dirent entry is virtual.
Returns
boolean
Always returns false for real entries.
offCommitError()
offCommitError(callback: (error: unknown, dirent: NVEDirent) => void): void;Removes a previously registered commit error callback.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | (error: unknown, dirent: NVEDirent) => void | The function to remove from the commitError event listeners. |
Returns
void
Example
const handler = (err, dirent) => { ... }
file.onCommitError(handler)
// ...
file.offCommitError(handler)onceCommitError()
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
| Parameter | Type | Description |
|---|---|---|
callback | (error: unknown, dirent: NVEDirent) => void | The function to call on the next commit error. Receives the error and the dirent instance. |
Returns
void
Example
file.onceCommitError((err, dirent) => {
alert("First commit failure!");
});onCommitError()
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
| Parameter | Type | Description |
|---|---|---|
callback | (error: unknown, dirent: NVEDirent) => void | The function to call on commit error. Receives the error and the dirent instance. |
Returns
void
Example
file.onCommitError((err, dirent) => {
console.error("Commit failed:", err);
});onWillDispose()
onWillDispose(callback: (dirent: NVEDirent) => void): void;Registers a callback to be invoked when this entry is disposed. The callback is only called once.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | (dirent: NVEDirent) => void | The function to call when disposed. |
Returns
void
toSerialized()
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.