Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stringify-tree

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stringify-tree

Turn a tree structure into an ascii tree

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.2K
increased by3.5%
Maintainers
1
Weekly downloads
 
Created
Source

stringify-tree

Convert a tree structure to an ASCII tree, in approximately the style of npm ls

This is in TypeScript, which helps since you pass it some functions.

install

npm install stringify-tree

trivial example

import { stringifyTree } from "stringify-tree";

const tree = {
        name: "Grandmarti", children: [
            {
                name: "Cyndi", children: [
                    {
                        name: "Jess", children: [
                            { name: "Evelyn", children: [] },
                            { name: "Linda", children: [] },
                        ],
                    },
                ],
            },
            { name: "Celia", children: [] },
        ],
    };
    console.log(stringifyTree(tree, t => t.name, t => t.children));
┬ Grandmarti
├─┬ Cyndi
│ └─┬ Jess
│   ├── Evelyn
│   └── Linda
└── Celia

real-life example

import { stringifyTree } from "stringify-tree";

function treeNodeName(tn: TreeNode) {
    const endOffset = tn.$value ? ", " + (tn.$offset + tn.$value.length) : "";
    return `[${tn.$offset}${endOffset}] ${tn.$name}`;
}
function treeNodeChildren(tn: TreeNode): TreeNode[] {
    return tn.$children || [];
}

// parser stuff from Atomist. trust me, it makes a TreeNode with fields like the above

const ast = await Java9FileParser.toAst(p.findFileSync(path));
console.log(stringifyTree<TreeNode>(ast, treeNodeName, treeNodeChildren));

Keywords

FAQs

Package last updated on 18 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc