Skip to content

Instantly share code, notes, and snippets.

@yonester
Created October 6, 2014 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yonester/ffa46f209b60b8d92755 to your computer and use it in GitHub Desktop.
Save yonester/ffa46f209b60b8d92755 to your computer and use it in GitHub Desktop.
Super simple pretty print
var _ = require('lodash');
// Pretty print for JSON-style objects.
function pprint(obj) {
if (!pprint.indent) pprint.indent = '';
if (_.isPlainObject(obj)) {
_.forOwn(obj, function(v, k) {
if (_.isArray(v) || _.isPlainObject(v)) {
console.log(pprint.indent + k + ':');
pprint.indent += ' ';
pprint(v);
pprint.indent = pprint.indent.slice(0, -2);
} else {
console.log(pprint.indent + k + ': ' + v);
}
});
} else if (_.isArray(obj)) {
_.each(obj, pprint);
} else {
console.log(pprint.indent + obj);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment