Skip to content
Local edited this page Apr 15, 2023 · 1 revision

For what?

This class represents methods for working with the virtual file system.

Everything inside the class is static, which guarantees a single virtual system in all applications.

Attributes

All class attributes are private, so information about them will be provided for project development.

Tree

private static tree: Record<string, any> = {};

The tree is a key part of the virtual file system and is an object, the keys of which must be strings, and the values ​​must be strings (which means that there is a file on the given path) or the same objects (which means that there is a directory on the given path).

Home

private static home: string = '';

Home - the path of the home folder, at startup the terminal is located in the home folder.

Methods

_parsePath

public static _parsePath(path: string): string[]

Removes '../' from the path, replacing with the parent directory.

getFolder

public static getFolder(path: string): Record<string, any> {

Returns the files and directories within the given path.

_getFolderWithoutLast

private static _getFolderWithoutLast(path: string): [Record<string, any>, string]

Wrapper over getFolder, used to get a folder by path and file name.

readFile

public static readFile(path: string): string | 'Uncorrected path'

Tries to give information along the path, if it doesn't work, then returns "Uncorrected path".

write

public static write(path: string, data: string | {})

Creates or modifies a file or folder at the given path.

remove

public static remove(path: string, recursion?: boolean)

Deletes a file or folder at the given path. To delete a folder, the recursion flag must be true.

export

public static export(): string

Returns the file system as a JSON string.

import

public static import(data: { [key: string]: any } | string, home?: string)

Sets the filesystem according to the passed object or JSON string. When passing the home parameter, the home attribute is set to the passed.

Clone this wiki locally