Skip to content

LLM Resources

@ascii-kit/tree - API documentation

Classes

Tree

Represents a utility for generating a directory structure string from an object.

Constructors

new Tree()
ts
new Tree(content: TreeContent, config?: TreeConfig): Tree

Creates an instance of the Tree generator.

Parameters
ParameterTypeDescription
contentTreeContentThe content object representing the directory structure.
config?TreeConfigAn object with options for generating the directory structure string.
Returns

Tree

Methods

generate()
ts
generate(): string

Generates the string representation of the directory structure.

Returns

string

A string representing the content of structure as a directory structure.

Properties

PropertyType
configTreeConfig
contentTreeContent

Functions

tree()

ts
function tree(content: TreeContent, opts?: TreeConfig): string

Returns a string representing the content of an object as a directory structure.

Parameters

ParameterTypeDescription
contentTreeContentThe content object representing the directory structure.
opts?TreeConfigAn object with options for generating the directory structure string.

Returns

string

A string representing the content of structure as a directory structure.

Example

ts
const result = tree({
  src: {
    components: {
      "Button.js": null,
      "Header.js": null
    },
    utils: {
      "helpers.js": null
    },
    "index.js": null
  },
  "package.json": null
  name: "my-project",
});

console.log(result);

Type Aliases

TreeConfig

ts
type TreeConfig: {
  hook: {
     onData: (data: TreeHookOptions) => TreeHookOptions;
     transform: (data: TreeHookOptions) => string;
    };
  pattern: TreePattern;
};

Defines the configuration options for generating the directory tree.

Type declaration

NameTypeDescription
hook?{ onData: (data: TreeHookOptions) => TreeHookOptions; transform: (data: TreeHookOptions) => string; }Hook functions to modify the data passed and style the tree.
hook.onData?(data: TreeHookOptions) => TreeHookOptionsA custom function to modify the data passed to the style functions.
hook.transform?(data: TreeHookOptions) => stringA custom function to style the tree.
pattern?TreePatternCustom pattern to use for indentation and line breaks.

TreeContent

ts
type TreeContent: {};

The content object representing the directory structure. A file is represented by null, and a folder by a nested TreeContent object.

Index Signature

[key: string]: null | Tree | TreeContent