Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
stringify-tree
Advanced tools
Readme
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.
npm install stringify-tree
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
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));
FAQs
Turn a tree structure into an ascii tree
The npm package stringify-tree receives a total of 161 weekly downloads. As such, stringify-tree popularity was classified as not popular.
We found that stringify-tree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.