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