JSPM

  • Created
  • Published
  • Downloads 4558
  • Score
    100M100P100Q137567F
  • License MIT

pretty print objects in real purdy colors. Allows clearer visualization of objects than you get from most pretty printers due to colors. It will also print out the complete path to an object, something that's extremly useful for debugging.

Package Exports

  • purdy

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 (purdy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Purdy

Print things real purdy for nodejs.

Usage

    var Purdy = require('purdy');
    Purdy({list: [1,2,3], string: 'some string'});

Purdy(object, [options])

Prints anything indented, and with arrays with index keys, and different types in colors such that it's very easy to get an overview of what object you're dealing with.

  • object - anything, number, object, array, etc.
  • options - optional object with the following keys.
    • plain - when true, prints result without colors. Defaults to false with tty, true when not.
    • path - when true, prints result with a path (To be used with Hoek.reach())
    • pathPrefix - prefix for path. default: //
    • arrayIndex - enables index printing for arrays. default: true

Purdy.stringify(object, [options])

This function returns a string without printing it to stdout. This may prove to be useful for log files other other applications.

var purdyString = Purdy.stringify({a: 'b'}, {plain: true});
writeLog(purdyString);

Examples

// var circularObj = { };
// circularObj.a = circularObj;
// var circ = [];
// circ.push(circ);
// Purdy({
//     a: 3,
//     bn: 'foo',
//     raino: it,
//     d: {king: 'cobra'},
//     null: null,
//     undefined: undefined,
//     regexp: new RegExp,
//     falseBool: false,
//     trueBool: true,
//     emptyArr: [],
//     circular: circularObj,
//     circularArr: circ
// });

{
              a: 3,
             bn: 'foo',
          raino: [Function: ?],
              d: {
        king: 'cobra'
    },
           null: null,
      undefined: undefined,
         regexp: /(?:)/,
      falseBool: false,
       trueBool: true,
       emptyArr: [],
       circular: {
        a: [Circular]
    },
    circularArr: [
        [0] [Circular]
    ]
}
```

```javascript
// Purdy([1,2,'foo', it, Array.isArray, new Date,1,1,1,1,12,[1,2]]);

[
    [ 0] 1,
    [ 1] 2,
    [ 2] 'foo',
    [ 3] [Function: ?],
    [ 4] [Function: isArray],
    [ 5] Tue May 06 2014 20:49:29 GMT-0700 (PDT),
    [ 6] 1,
    [ 7] 1,
    [ 8] 1,
    [ 9] 1,
    [10] 12,
    [11] [
        [0] 1,
        [1] 2
    ]
]
```

``` javascript
// var obj = {
//     travel: {
//         down: {
//             a: [{
//                 path: 'to get here'
//             }]
//         }
//     }
// Purdy(obj, { path: true });

{
    travel: {
        // travel.down
        down: {
            // travel.down.a
              a: [
                // travel.down.a.0
                [0] {
                    // travel.down.a.0.path
                    path: 'to get here'
                }
            ]
        }
    }
}

// var Hoek = require('hoek');
// Purdy(Hoek.reach(obj, 'travel.down.a.0.path'));

{
        path: 'to get here'
}

```



## Acknowledgements
* Michael Dvorkin for [Awesome Print]

[Awesome Print]: https://github.com/michaeldv/awesome_print