UNPKG

3.13 kBMarkdownView Raw
1# Purdy
2
3Print things real purdy for nodejs.
4
5## Usage
6
7```javascript
8 var Purdy = require('purdy');
9 Purdy({list: [1,2,3], string: 'some string'});
10```
11
12### `Purdy(object, [options])`
13
14Prints anything indented, and with arrays with index keys, and different
15types in colors such that it's very easy to get an overview of what object
16you're dealing with.
17
18* `object` - anything, number, object, array, etc.
19* `options` - optional object with the following keys.
20 * `plain` - when `true`, prints result without colors. Defaults to `false` with tty, `true` when not.
21 * `path` - when `true`, prints result with a path (To be used with [Hoek.reach()](https://github.com/spumko/hoek#reachobj-chain-options))
22 * `pathPrefix` - prefix for path. default: `// `
23 * `arrayIndex` - enables index printing for arrays. default: `true`
24 * `indent` - defines the number of spaces to indent default: `4`
25 * `align` - determines how to align object keys. default: `left`
26
27
28### `Purdy.stringify(object, [options])`
29
30This function returns a string without printing it to stdout. This may prove
31to be useful for log files other other applications.
32
33``` javascript
34var purdyString = Purdy.stringify({a: 'b'}, {plain: true});
35writeLog(purdyString);
36```
37
38### Examples
39
40````javascript
41// var circularObj = { };
42// circularObj.a = circularObj;
43// var circ = [];
44// circ.push(circ);
45// Purdy({
46// a: 3,
47// bn: 'foo',
48// raino: it,
49// d: {king: 'cobra'},
50// null: null,
51// undefined: undefined,
52// regexp: new RegExp,
53// falseBool: false,
54// trueBool: true,
55// emptyArr: [],
56// circular: circularObj,
57// circularArr: circ
58// });
59
60{
61 a: 3,
62 bn: 'foo',
63 raino: [Function: ?],
64 d: {
65 king: 'cobra'
66 },
67 null: null,
68 undefined: undefined,
69 regexp: /(?:)/,
70 falseBool: false,
71 trueBool: true,
72 emptyArr: [],
73 circular: {
74 a: [Circular]
75 },
76 circularArr: [
77 [0] [Circular]
78 ]
79}
80```
81
82```javascript
83// Purdy([1,2,'foo', it, Array.isArray, new Date,1,1,1,1,12,[1,2]]);
84
85[
86 [ 0] 1,
87 [ 1] 2,
88 [ 2] 'foo',
89 [ 3] [Function: ?],
90 [ 4] [Function: isArray],
91 [ 5] Tue May 06 2014 20:49:29 GMT-0700 (PDT),
92 [ 6] 1,
93 [ 7] 1,
94 [ 8] 1,
95 [ 9] 1,
96 [10] 12,
97 [11] [
98 [0] 1,
99 [1] 2
100 ]
101]
102```
103
104``` javascript
105// var obj = {
106// travel: {
107// down: {
108// a: [{
109// path: 'to get here'
110// }]
111// }
112// }
113// Purdy(obj, { path: true });
114
115{
116 travel: {
117 // travel.down
118 down: {
119 // travel.down.a
120 a: [
121 // travel.down.a.0
122 [0] {
123 // travel.down.a.0.path
124 path: 'to get here'
125 }
126 ]
127 }
128 }
129}
130
131// var Hoek = require('hoek');
132// Purdy(Hoek.reach(obj, 'travel.down.a.0.path'));
133
134{
135 path: 'to get here'
136}
137
138```
139
140
141
142## Acknowledgements
143* Michael Dvorkin for [Awesome Print]
144
145[Awesome Print]: https://github.com/michaeldv/awesome_print