I made a library to print object as a tree structure like the unix tree command
Muhammad Sifat Hossain
Posted on October 15, 2022
I'm currently working on a project where I have some hierarchical data that need's to be printed in the console as a tree structure.
At first, I thought let me see if it's available on npm. But before going to npm I told myself: "Why don't I try it myself first?". So I started working on it and by the time I finished it I realized that it's 2 am in the morning š . Today I've published the library on npm. It's called flexible-tree-printer.
Example:
import { printTree } from "flexible-tree-printer";
const categories = {
study: {
academic: { Math: null, English: null },
programming: {
DSA: null,
"Number Theory": {},
Backend: {
"Node.Js": {},
Sqlite: {},
},
},
},
work: {
personal_projects: null,
job: {},
},
};
printTree({
parentNode: categories,
printRootNode: () => console.log("categories"),
});
Running the above snippet produces the following result:
categories
āāā study
ā āāā academic
ā ā āāā Math
ā ā āāā English
ā āāā programming
ā āāā DSA
ā āāā Number Theory
ā āāā Backend
ā āāā Node.Js
ā āāā Sqlite
āāā work
āāā personal_projects
āāā job
Almost every behavior of printing is customizable and the library has a very flexible API.
I would love to hear your feedback and kindly give it a ā GitHub if you find it interesting.
Posted on October 15, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
October 15, 2022