npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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 of FolderNode 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: A FolderNode 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: The key 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.