Created
September 17, 2014 01:37
-
-
Save ferronrsmith/ceccd35cca6dbfe3cd20 to your computer and use it in GitHub Desktop.
node-logging prettyPrintObj.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/Monwara/node-logging/blob/master/logging.js | |
function prettyPrintObj(o, excludes) { | |
excludes = typeof excludes === 'undefined' ? EXCLUDES : excludes; | |
if (!o || typeof o !== 'object' || !Object.keys(o).length) { | |
return '*'.grey + ' ' + 'n/a'.green + '\n'; | |
} | |
var rows = []; | |
Object.keys(o).forEach(function(key) { | |
var value; | |
if (excludes.length && excludes.indexOf(key) < 0) { | |
if (o[key] === null) { | |
value = 'null'.grey; | |
} else if (typeof o[key] === 'undefined') { | |
value = 'undefined'.grey; | |
} else { | |
value = o[key].toString(); | |
} | |
} else { | |
value = '(excluded)'.grey; | |
} | |
rows.push('*'.grey + ' ' + key.green + ': ' + value); | |
}); | |
return rows.join('\n') + '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment