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.
Top comments (0)