Purdy
Print things real purdy for nodejs.
Usage
const Purdy = ; ;
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
- whentrue
, prints result without colors. Defaults tofalse
with tty,true
when not.path
- whentrue
, prints result with a path (To be used with Hoek.reach())pathPrefix
- prefix for path. default://
arrayIndex
- enables index printing for arrays. default:true
indent
- defines the number of spaces to indent default:4
align
- determines how to align object keys. default:left
depth
- tells purdy how many times to recurse while formatting the object. This is useful for viewing complicated objects. default:2
. Set tonull
to recurse indefinitely
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.
const purdyString = Purdy;;
Examples
The following code prints what's in the image above.
const mises = { thismoop = 3 }const instance = ;const circularObj = ;circularObja = circularObj;const obj =integer: Datestring: 'foo'anonPurdy: Purdy{}nested: hello: 'hapi'error: 'bad'null: nullundefined: undefinedregexp:falseBool: falsetrueBool: truesymbol: Symbol'purdy'emptyArr:circular: circularObjdate:arrayWithVisibleIndex: 'one' 'two' 'three'instance: instance;;
Command-line Interface
This package also installs the purdy
CLI tool. Right now this just prints
any JSON file with default options.
purdy package.json
will, for example, print the JSON contents of
package.json.
Similarly, cat package.json | purdy -s
will use stdin to print the contents.
A new option -l
has been added to parse log files that has one JSON string per line in the file.
purdy -l logfile.log
will print that.
Contributing
This project adheres to the hapi styleguide.
Acknowledgements
- Michael Dvorkin for Awesome Print