Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The treeify npm package is used to convert a flat, nested object into a visual tree structure. This can be useful for displaying hierarchical data in a more readable format, such as in command-line tools or debugging outputs.
Convert object to tree
This feature allows you to convert a nested object into a string that visually represents a tree structure. The 'asTree' method takes the object and a boolean indicating whether to show empty values.
const treeify = require('treeify');
let tree = treeify.asTree({hello: 'world', foo: {bar: 'baz'}}, true);
console.log(tree);
Custom sorting of tree branches
This feature allows you to provide a custom sorting function for the keys of your object, which will affect the order in which branches are displayed in the tree.
const treeify = require('treeify');
let tree = treeify.asTree({foo: {bar: 'baz'}, hello: 'world'}, true, (a, b) => a.localeCompare(b));
console.log(tree);
Archy is an npm package that also allows you to render nested hierarchies with a tree structure. It is similar to treeify but has a different API and focuses on creating ASCII trees, which can be useful for command-line utilities.
Ascii-tree is another npm package that generates ASCII trees from a flat string with indentation to represent the hierarchy. It differs from treeify in that it starts with a string representation of the tree rather than an object.
treeify converts a JS object into a nice, visible depth-indented tree for console printing. The structure
generated is similar to what you get by running the tree
command on Unixy platforms.
{
oranges: {
'mandarin': { ├─ oranges
clementine: null, │ └─ mandarin
tangerine: 'so cheap and juicy!' -=> │ ├─ clementine
} │ └─ tangerine: so cheap and juicy!
}, └─ apples
apples: { ├─ gala
'gala': null, └─ pink lady
'pink lady': null
}
}
It also works well with larger nested hierarchies such as file system directory trees.
In fact, the fs_tree
example does a pretty good job of imitating tree
. Try it out!
See the other included examples or the test suite for usage scenarios.
First you'll want to run this command in your project's root folder:
$ npm install treeify
Then proceed to use it in your project:
var treeify = require('treeify');
console.log(
treeify.asTree({
apples: 'gala', // ├─ apples: gala
oranges: 'mandarin' // └─ oranges: mandarin
}, true)
);
Treeify cooperates with Node, AMD or browser globals to create a module. This means it'll work
in a browser regardless of whether you have an AMD-compliant module loader or not. If such
a loader isn't found when the script is executed, you may access Treeify at window.treeify
.
The methods exposed to you are as follows, in a strange kind of signature notation:
treeify.asLines(obj, showValues (boolean), [hideFunctions (boolean),] lineCallback (function))
// NOTE: hideFunctions is optional and may be safely omitted - this was done to ensure we don't break uses of the previous form
treeify.asTree(obj, showValues (boolean), hideFunctions (boolean)): String
There's a pretty extensive suite of Vows tests included.
$ npm test
FAQs
converts a JS object into a nice and readable tree structure for the console
The npm package treeify receives a total of 836,761 weekly downloads. As such, treeify popularity was classified as popular.
We found that treeify 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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.