this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

1# 🪾 `array-treeify` 2 3**Simple ASCII trees from arrays. For your terminal and console displays.** 4 5[![typescript](https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/) 6[![npm](https://img.shields.io/npm/v/array-treeify.svg)](https://www.npmjs.com/package/array-treeify) 7[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/tbeseda/array-treeify/blob/main/LICENSE) 8 9## Overview 10 11`array-treeify` transforms nested arrays into beautiful ASCII trees with proper branching characters. Perfect for CLIs, debug outputs, or anywhere you need to visualize hierarchical data. 12 13``` 14Lumon Industries 15├─ Board of Directors 16│ └─ Natalie (Representative) 17├─ Departments 18│ └─ Macrodata Refinement (Cobel) 19│ ├─ Milchick 20│ └─ Mark S. 21│ ├─ Dylan G. 22│ ├─ Irving B. 23│ └─ Helly R. 24└─ Other Departments 25 ├─ Optics & Design 26 ├─ Wellness Center 27 ├─ Mammalians Nurturable 28 └─ Choreography and Merriment 29``` 30 31## Installation 32 33```bash 34npm install array-treeify 35``` 36 37## Usage 38 39```typescript 40function treeify(input: TreeInput): string 41``` 42 43`array-treeify` accepts a simple, intuitive array structure that's easy to build and manipulate: 44 45```typescript 46import {treeify} from 'array-treeify' 47 48// Basic example 49const eagan = [ 50 'Kier Eagan', 51 [ 52 '...', 53 [ 54 '...', 55 'Jame Eagan', 56 ['Helena Eagan'] 57 ], 58 ], 59 'Ambrose Eagan' 60] 61console.log(treeify(eagan)) 62/* 63Kier Eagan 64├─ ... 65| ├─ ... 66| └─ Jame Eagan 67| └─ Helena Eagan 68└─ Ambrose Eagan 69*/ 70 71// Nested example 72const orgChart = [ 73 'Lumon Industries', 74 [ 75 'Board of Directors', 76 ['Natalie (Representative)'], 77 'Department Heads', 78 [ 79 'Cobel (MDR)', 80 ['Milchick', 'Mark S.', ['Dylan G.', 'Irving B.', 'Helly R.']] 81 ] 82 ] 83] 84console.log(treeify(orgChart)) 85/* 86Lumon Industries 87├─ Board of Directors 88│ └─ Natalie (Representative) 89└─ Department Heads 90 └─ Cobel (MDR) 91 ├─ Milchick 92 └─ Mark S. 93 ├─ Dylan G. 94 ├─ Irving B. 95 └─ Helly R. 96*/ 97``` 98 99## Input Format 100 101The `treeify` function accepts arrays with the following structure: 102 1031. First element must be a string (the root node) 1042. Subsequent elements can be strings (nodes at same level) or arrays (children of previous node) 1053. Arrays can be nested to any depth 106 107```typescript 108['root', 'sibling', ['child1', 'child2']] // Root with 2 children 109['root', ['child'], 'sibling', ['nephew', 'niece']] // 2 root nodes with children 110['root', ['child', ['grandchild']]] // Grandchildren 111``` 112 113## License 114 115MIT © tbeseda