Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing giving specific colors to certain JSON object keys/values #17

Open
mdedetrich opened this issue Jun 23, 2020 · 2 comments
Open

Comments

@mdedetrich
Copy link

mdedetrich commented Jun 23, 2020

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?

@mdedetrich mdedetrich changed the title Allowing giving specific colors to certain JSON object keys Allowing giving specific colors to certain JSON object keys/values Jun 23, 2020
@joeattardi
Copy link
Owner

That would be really cool!

@mdedetrich
Copy link
Author

Awesome, I will look try and cook up a PR when I have time (this week or more likely next week).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants