@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): TreeCreates an instance of the Tree generator.
Parameters
| Parameter | Type | Description |
|---|---|---|
content | TreeContent | The content object representing the directory structure. |
config? | TreeConfig | An object with options for generating the directory structure string. |
Returns
Methods
generate()
ts
generate(): stringGenerates the string representation of the directory structure.
Returns
string
A string representing the content of structure as a directory structure.
Properties
| Property | Type |
|---|---|
config | TreeConfig |
content | TreeContent |
Functions
tree()
ts
function tree(content: TreeContent, opts?: TreeConfig): stringReturns a string representing the content of an object as a directory structure.
Parameters
| Parameter | Type | Description |
|---|---|---|
content | TreeContent | The content object representing the directory structure. |
opts? | TreeConfig | An 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
| Name | Type | Description |
|---|---|---|
hook? | { onData: (data: TreeHookOptions) => TreeHookOptions; transform: (data: TreeHookOptions) => string; } | Hook functions to modify the data passed and style the tree. |
hook.onData? | (data: TreeHookOptions) => TreeHookOptions | A custom function to modify the data passed to the style functions. |
hook.transform? | (data: TreeHookOptions) => string | A custom function to style the tree. |
pattern? | TreePattern | Custom 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
