npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

array-treeify

v0.1.5

Published

Simple text tree diagrams from arrays.

Readme

🪾 array-treeify

Simple text trees from arrays using Unicode box-drawing characters. For your terminal and console displays.

typescript npm license

Overview

array-treeify transforms nested arrays into text trees with proper branching characters. Perfect for CLIs, debug outputs, or anywhere you need to visualize hierarchical data.

treeify([
  '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',
    ],
  ],
])
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, options?: {
  chars?: TreeChars,  // Custom characters for the tree
  plain?: boolean     // Use plain whitespace instead of Unicode box-drawing characters
}): 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
*/

// Using custom characters
const resultCustomChars = treeify(
  eagan, 
  { chars: { branch: '├• ', lastBranch: '└• ', pipe: '│  ', space: '   ' },
})
/*
Kier Eagan
├• ...
│  ├• ...
│  └• Jame Eagan
│     └• Helena Eagan
└• Ambrose Eagan
*/

// Using plain whitespace characters
console.log(treeify(eagan, { plain: true }))
/*
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

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:

  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

Options

  • chars: Custom characters for the tree. Defaults to Unicode box-drawing characters.
  • plain: When true, uses plain whitespace characters instead of Unicode box-drawing characters.

License

MIT © tbeseda