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 🙏

© 2024 – Pkg Stats / Ryan Hefner

formatree

v1.0.2

Published

Format a tree like structure to a depth indented string

Downloads

56

Readme

formatree

Format a tree like structure to a depth indented string

Install

$ npm i -g formatree

Usage

const formatree = require('formatree');
const tree = { foo: { bar: 0 }, baz: 1, qux: { quux: 2 } };
formatree(tree);
// .
// ├── foo
// │   └── bar
// ├── baz
// └── qux
//     └── quux
// 
formatree(tree, { limit: 1, spacing: 1, values: true });
// .
// │   
// ├── foo
// │   
// ├── baz (1)
// │   
// └── qux
// 
formatree(tree, { sibling: '|-- ', lastSibling: '`-- ', indent: '|   ' });
// .
// |-- foo
// |   `-- bar
// |-- baz
// `-- qux
//     `-- quux
// 

API

formatree(input, [options])

input

Type: object

The tree structure that needs to be formatted.

options

Type: Object

limit

Type: number
Default: 0

Limit the tree at a specific branch depth, 0 is no limit.

spacing

Type: number
Default: 0

Add some extra lines between the tree branches, 0 is no spacing.

values

Type: boolean
Default: false

Show the values of the siblings in the tree

header

Type: string
Default: .

The first line of the tree

footer

Type: string
Default: \n

The last line of the tree

sibling

Type: string
Default: ├──

lastSibling

Type: string
Default: └──

indent

Type: string
Default:

lastIndent

Type: string
Default:

parent

Type: string
Default: ``

Append a string after a parent branch in the tree

Themes

ASCII
{sibling: '|-- ',lastSibling: '`-- ',indent: '|   '}
Clean
{header: '',sibling: ' ',lastSibling: ' ',indent: '  ',lastIndent: '  ', footer: ''}
101010
{header: '0',sibling: '101 ',lastSibling: '101 ',indent: '1010',lastIndent: '1010'}
Stripes
{sibling: '─ ',lastSibling: '─ ',indent: '──',lastIndent: '──'}
Arrows
{header: 'v',sibling: '> ',lastSibling: '> ',indent: '>>',lastIndent: '>>', footer: '^'}

Related

License

MIT © A1rPun