this repo has no description
0
fork

Configure Feed

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

TypeScript 100.0%
5 1 5

Clone this repository

https://tangled.org/tbeseda.com/array-treeify https://tangled.org/did:plc:hhpir4z3l4fwmotc2cvka6ln/array-treeify
git@tangled.org:tbeseda.com/array-treeify git@tangled.org:did:plc:hhpir4z3l4fwmotc2cvka6ln/array-treeify

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

🪾 array-treeify#

Simple ASCII trees from arrays. For your terminal and console displays.

typescript npm license

Overview#

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.

Lumon Industries
├─ Board of Directors
│  └─ Natalie (Representative)
├─ Departments
│  └─ Macrodata Refinement (Cobel)
│     ├─ Milchick
│     └─ Mark S.
│        ├─ Dylan G.
│        ├─ Irving B.
│        └─ Helly R.
└─ Other Departments
   ├─ Optics & Design
   ├─ Wellness Center
   ├─ Mammalians Nurturable
   └─ Choreography and Merriment

Installation#

npm install array-treeify

Usage#

function treeify(input: TreeInput): string

array-treeify accepts a simple, intuitive array structure that's easy to build and manipulate:

import {treeify} from 'array-treeify'

// Basic example
const eagan = [
  'Kier Eagan', 
  [
    '...',
    [
      '...',
      'Jame Eagan',
      ['Helena Eagan']
    ],
    'Ambrose Eagan',
  ],
]
console.log(treeify(eagan))
/*
Kier Eagan
├─ ...
│  ├─ ...
│  └─ Jame Eagan
│     └─ Helena Eagan
└─ Ambrose Eagan
*/

// Nested example
const orgChart = [
  'Lumon Industries',
  [
    'Board of Directors',
    ['Natalie (Representative)'],
    'Department Heads',
    [
      'Cobel (MDR)',
      ['Milchick', 'Mark S.', ['Dylan G.', 'Irving B.', 'Helly R.']]
    ]
  ]
]
console.log(treeify(orgChart))
/*
Lumon Industries
├─ Board of Directors
│  └─ Natalie (Representative)
└─ Department Heads
   └─ Cobel (MDR)
      ├─ Milchick
      └─ Mark S.
         ├─ Dylan G.
         ├─ Irving B.
         └─ Helly R.
*/

Input Format#

The treeify function accepts arrays with the following structure:

  1. First element must be a string (the root node)
  2. Subsequent elements can be strings (nodes at same level) or arrays (children of previous node)
  3. Arrays can be nested to any depth
['root', 'sibling', ['child1', 'child2']]             // Root with 2 children
['root', ['child'], 'sibling', ['nephew', 'niece']]   // 2 root nodes with children
['root', ['child', ['grandchild']]]                   // Grandchildren

License#

MIT © tbeseda