json-colorizer
json-colorizer copied to clipboard
Allowing giving specific colors to certain JSON object keys/values
The basic idea is to add an ability that lets you give specific colors to specific keys for any JSON object that you happen to colorize. For example you can do something like
console.log(colorize({ "uri": "localhost:3000", "status":404}, {
colors: {
JSON_OBJECT_CUSTOM: function (key, value, currentJsonObject) {
if (key === 'status' && currentJsonObject.hasOwnProperty('uri')) {
if (value.toString.startsWith('2')) {
return 'green';
} else if (value.toString.startsWith('3') {
return 'orange';
} else if (value.toString.startsWith('4') {
return 'red';
} else if (value.toString.startsWith('5') {
return 'red';
}
return null; // If we return null then we just use original color.
}
};
}
}));
Would you be open to such functionality or is this considered scope creep?
That would be really cool!
Awesome, I will look try and cook up a PR when I have time (this week or more likely next week).