Skip to content

Instantly share code, notes, and snippets.

@Gergling
Created February 17, 2015 15:07
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 Gergling/c4f1a2ff2b2b8726f66e to your computer and use it in GitHub Desktop.
Save Gergling/c4f1a2ff2b2b8726f66e to your computer and use it in GitHub Desktop.
A recursive printing function, similar to PHP's print_r.
var printR = function (obj, indent) {
indent = indent || 0;
if (typeof obj === "string") {
grunt.log.writeln("'" + obj + "'");
} else if (typeof obj === "object") {
grunt.log.writeln("{");
Object.keys(obj).forEach(function (key) {
grunt.log.write(repeat(" ", indent + 2) + key + ": ");
printR(obj[key], indent + 1);
});
grunt.log.writeln(repeat(" ", indent + 1) + "}");
} else {
grunt.log.writeln(obj);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment