dynamic-folders
v1.0.21
Published
## Overview
Downloads
159
Readme
DynamicFolders Documentation
Overview
The DynamicFolders
class provides a flexible way to represent and manipulate a hierarchical folder structure. This structure is defined using FolderNode
objects, which can include conditions, options, and subfolders. The class offers various methods to interact with this structure, such as retrieving inputs for a given path, validating folder paths, and generating folder names.
Interface
FolderNode
The FolderNode
interface represents a node in the folder structure.
export interface FolderNode {
key: string;
ignore_duplicate: boolean;
options?: string[];
condition?: {
[key: string]: string;
};
subfolders?: FolderNode[];
}
key
: A unique identifier for the folder node.ignore_duplicate
: A boolean that indicates whether duplicate folder names should be ignored.options
: (Optional) An array of strings representing the allowed options for this node.condition
: (Optional) An object that defines conditions to select a subfolder based on the value of another node.subfolders
: (Optional) An array ofFolderNode
objects representing subfolders of the current node.
ValidationError
The ValidationError
class extends the native Error
class and is used to signal validation errors in the DynamicFolders
class.
export class ValidationError extends Error {
constructor(message: string) {
super(message);
Object.setPrototypeOf(this, ValidationError.prototype);
}
}
Class: DynamicFolders
Constructor
constructor(data: FolderNode)
data
: AFolderNode
object representing the root of the folder structure.
Methods
getInputs(path: string)
Returns an array of inputs corresponding to the specified path.
getInputs(path: string): { key: string; options?: string[]; dynamic: boolean }[]
path
: A string representing the path (e.g.,"Fachgruppe/Bioinformatik/Jerome/Project/test"
).- Returns: An array of objects containing:
key
: Thekey
of the current folder node.options
: The available options for this node (if any).dynamic
: A boolean indicating whether the node is dynamic (i.e., has conditions).
validateFolder(path: string)
Validates the folder structure against the provided path.
validateFolder(path: string): void
path
: A string representing the folder path.- Throws:
ValidationError
if the path is invalid.
getFolders(path: string)
Returns an array of folder objects representing the folder structure for the given path.
getFolders(path: string): { name: string; ignore_duplicate: boolean }[]
path
: A string representing the folder path.- Returns: An array of objects containing:
name
: The folder name.ignore_duplicate
: A boolean indicating whether duplicates should be ignored for this folder.
getDefaults()
Returns the default values for the folder structure.
getDefaults(): Record<string, string>
- Returns: An object where each key is a folder node's
key
and the value is the default option for that node.
Utility Function
createVmName(fields: Record<string, string>, name: string)
Creates a virtual machine name based on user fields.
export const createVmName = (fields: Record<string, string>, name: string): string
fields
: An object where keys are field names and values are field values (e.g.,{ user: "John Doe" }
).name
: The base name for the virtual machine.- Returns: A string representing the generated VM name.