Class Treegen

The Treegen class provides functionality for generating and working with directory tree structures.

Hierarchy

  • Treegen

Constructors

Methods

  • Generates a tree structure from a directory path or a provided Treegen structure.

    Parameters

    • options: {
          dirPath?: string;
          ignoreRules?: RegExp[];
          rootName?: string;
          structure?: "\n" | ` ${string}>${string}` | `${string}>${string} ` | `${string}>${string} ${string}>${string}`;
          useTypeMarker?: boolean;
      }

      Options for generating the tree structure.

      • Optional dirPath?: string

        The path to the directory to scan.

      • Optional ignoreRules?: RegExp[]

        An array of regular expressions used to ignore specific files or directories.

      • Optional rootName?: string

        The name of the root directory in the structure. Default: 'root'

      • Optional structure?: "\n" | ` ${string}>${string}` | `${string}>${string} ` | `${string}>${string} ${string}>${string}`

        A Treegen structure to use (optional).

      • Optional useTypeMarker?: boolean

        Indicates whether to use type markers in the structure. Default: false

    Returns Node

    The root Node of the generated tree structure.

    Throws

    If the provided structure is not a valid Treegen structure.

  • Checks whether the provided structure is a valid Treegen structure.

    Parameters

    • structure: string

      The Treegen structure to validate.

    • root: string = 'root'

      The name of the root directory in the structure. Default: 'root'

    Returns boolean

    True if the structure is valid, false otherwise.

  • Parse ignore rules.

    Parameters

    • ignoreRules: (string | RegExp)[]

      An array of regular expressions used to determine if the file should be ignored.

    Returns RegExp[]

  • Recursively scans a directory and generates a Treegen structure representing its contents.

    Parameters

    • options: {
          dirPath?: string;
          ignoreRules?: (string | RegExp)[];
          root?: string;
          typeMarker?: boolean;
      }

      Options for scanning the directory and generating the structure.

      • Optional dirPath?: string

        The path to the directory to scan. Default: './'

      • Optional ignoreRules?: (string | RegExp)[]

        An array of regular expressions used to ignore specific files or directories.

      • Optional root?: string

        The name of the root directory in the structure. Default: 'root'

      • Optional typeMarker?: boolean

        Indicates whether to include type markers in the structure for files and directories. Default: false

    Returns "\n" | ` ${string}>${string}` | `${string}>${string} ` | `${string}>${string} ${string}>${string}`

    A Treegen structure representing the directory's contents.

  • Determines whether a filename should be ignored based on a list of ignore rules.

    Parameters

    • filename: string

      The name of the file to check.

    • ignoreRules: RegExp[] = []

      An array of regular expressions used to determine if the file should be ignored.

    Returns boolean

    True if the filename should be ignored, false otherwise.

Generated using TypeDoc