array-treeify
Advanced tools
+5
-7
| /** | ||
| * Represents a node in the tree structure. | ||
| * Can be either a string (a leaf node) or an array of TreeNodes (a branch with children). | ||
| */ | ||
| type TreeNode = string | TreeNode[]; | ||
| /** | ||
| * The strict tree input format. Must start with a string. | ||
| * This type is exported for testing purposes and advanced usage. | ||
| */ | ||
| export type TreeInput = [string, ...Array<string | TreeNode[]>] | string[]; | ||
| export type TreeInput = Array<string | TreeInput>; | ||
| /** | ||
@@ -16,3 +11,6 @@ * Flexible input type that accepts any array. | ||
| type FlexibleTreeInput = readonly (string | unknown[])[]; | ||
| type TreeChars = { | ||
| /** | ||
| * ASCII characters used to render the tree. | ||
| */ | ||
| export type TreeChars = { | ||
| branch: string; | ||
@@ -19,0 +17,0 @@ lastBranch: string; |
+0
-3
@@ -1,4 +0,1 @@ | ||
| /** | ||
| * @description ASCII characters used to render the tree. | ||
| */ | ||
| const DEFAULT_CHARS = { | ||
@@ -5,0 +2,0 @@ branch: '├─ ', |
+1
-1
| { | ||
| "name": "array-treeify", | ||
| "version": "0.1.4", | ||
| "version": "0.1.5", | ||
| "description": "Simple text tree diagrams from arrays.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+3
-0
@@ -152,2 +152,5 @@ # `array-treeify` | ||
| > **Disclaimer:** | ||
| > The exported `TreeInput` type (`Array<string | TreeInput>`) is intentionally flexible to support dynamic and programmatic tree construction. However, TypeScript cannot enforce at the type level that the first element is a string. This requirement is checked at runtime by the `treeify` function, which will throw an error if the first element is not a string. Please ensure your input arrays follow this convention. | ||
| The `treeify` function accepts arrays with the following structure: | ||
@@ -154,0 +157,0 @@ |
12949
1.78%175
1.74%205
-2.38%