JSPM

  • Created
  • Published
  • Downloads 18228
  • Score
    100M100P100Q133081F
  • License MIT

Make your JSONE look AWESOME!

Package Exports

  • jsome

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jsome) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Make your JSON objects look AWESOME !!

Jsome

This package allows you to give style to your JSON on your console!

##Installation :

$ npm install jsome

##How does it work ?

on your nodejs application, when you need to console.log a json object, all you need to do is to use the jsome function

    var jsome = require('jsome');
    jsome([{"id":1,"email":"Khalid@Morocco.ma","active":true},{"id":2,"email":"Someone@somewhere.com","active":false},{"id":3,"email":"chinese@bamboo.tree","active":true}]);

Then your json object will be displayed on the console in a pretty format with Awsome colors ! Here is the result :

jsome

You can add some points to show levels of elements... very helpful when you are dealing with complex json objects

    jsome.level.show = true;

jsome

The object jsome.level has as default value the following json :

  jsome.level = {
      'show'    : false
    , 'char'    : '.'
    , 'color'   : 'red'
    , 'spaces'  : 2
  }

You can change the level char, its color ( see colors package ) and the number of spaces for each level.

You can configure the colors of the displayed json by changing the values of the jsome.colors object which has as default these values.

  jsome.colors = {
      'num'   : 'cyan'
    , 'str'	: 'magenta'
    , 'bool'  : 'red'
    , 'undef' : 'grey'
    , 'null'  : 'grey'
    , 'attr'  : 'green'
    , 'quot'  : 'yellow'
    , 'punc'  : 'yellow'
    , 'brack' : 'yellow'
  }

When you have a json as a string, instead of passing by JSON.parse function, you can just call the parse function of jsome

  jsome(JSON.parse('[1,2,3]'));

becomes:

  jsome.parse('[1,2,3]');

If you need to disable the colors:

  jsome.params.colored = false;

When you have a very long json to display, don't make your code blocking... you can enable the asynchronous mode.

jsome.global.async = true;

jsome(longJson, function () {
    /* Your code here */
});

The default value of params is:

  jsome.params = {
      'colored' : true
    , 'async'   : false
  }