Socket
Socket
Sign inDemoInstall

treeify

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

treeify - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

2

package.json
{
"name": "treeify",
"version": "0.2.0",
"version": "0.3.0",
"author": "Luke Plaster <notatestuser@gmail.com>",

@@ -5,0 +5,0 @@ "description": "converts a JS object into a nice, visible tree structure for the console",

@@ -46,2 +46,12 @@ node-treeify

The methods exposed to you are as follows, in a strange kind of signature notation:
### asLines()
```js
treeify.asLines(obj, showValues (boolean), lineCallback (function))
```
### asTree()
```js
treeify.asTree(obj, showValues (boolean), hideFunctions (boolean)): String
```
Running the tests

@@ -48,0 +58,0 @@ -----------------

@@ -21,4 +21,4 @@ var treeify = require('../treeify'),

function treeifyEntirely(obj) {
return function(showValues) {
return treeify.asTree(obj, showValues);
return function(showValues, hideFunctions) {
return treeify.asTree(obj, showValues, hideFunctions);
};

@@ -28,5 +28,10 @@ }

function withValuesShown(showValues) {
return function(func){ return func(showValues) };
return function(func){ return func(showValues, false) };
}
function withValuesShownFunctionsHidden() {
return function(func){ return func(true, true) };
}
function is(content, arrayIndex) {

@@ -288,4 +293,29 @@ return function(lines) {

}
},
'A tree with functions': {
topic: {
func:function(){},
Friendly:"stuff",
Another:"stuff"
},
'when returned as a whole tree': {
topic: treeifyEntirely,
'with values shown, but functions hidden': {
topic: withValuesShownFunctionsHidden(),
'and split into an array of lines': {
topic: function(tree) {
console.error(tree);
return tree.split(/\n/g) },
'is a one liner output (with a following blank line)': function(lines) {
assert.equal(lines.length, 3);
},
'has a correct first line': is('├─ Friendly: stuff', 0)
}
}
}
}
}).export(module);

@@ -25,3 +25,3 @@ // treeify.js

function growBranch(key, root, last, lastStates, showValues, callback) {
function growBranch(key, root, last, lastStates, showValues, hideFunctions, callback) {
var line = '', index = 0, lastKey, circular, lastStatesCopy = lastStates.slice(0);

@@ -56,8 +56,11 @@

// always exclude anything in the object's prototype
if ( ! root.hasOwnProperty(branch)) {
if (!root.hasOwnProperty(branch)) {
continue;
}
if (hideFunctions&& ((typeof root[branch])==="function")) {
continue;
}
// hold your breath for recursive action
lastKey = ++index === Object.keys(root).length;
growBranch(branch, root[branch], lastKey, lastStatesCopy, showValues, callback);
growBranch(branch, root[branch], lastKey, lastStatesCopy, showValues, hideFunctions, callback);
}

@@ -79,5 +82,5 @@ }

Treeify.asTree = function(obj, showValues) {
Treeify.asTree = function(obj, showValues, hideFunctions) {
var tree = '';
growBranch('.', obj, false, [], showValues, function(line) {
growBranch('.', obj, false, [], showValues, hideFunctions, function(line) {
tree += line + '\n';

@@ -87,3 +90,4 @@ });

};
})();
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