Stringify any JavaScript value.
- Supports all built-in JavaScript types
- Blazingly fast (similar performance to v8's
JSON.stringify
and significantly faster than Node'sutil.format
) - Plugin system for extending with custom types (i.e.
ReactTestComponent
)
Installation
$ npm install @ava/pretty-format
Usage
var prettyFormat = ; var obj = property: {} ;objcircularReference = obj;objSymbol'foo' = 'foo';objmap = ;objmap;objarray = 1 NaN Infinity; console;
Result:
Object "property": Object {} "circularReference": Circular "map": Map "prop" "value" "array": Array 1 NaN Infinity Symbolfoo: "foo"
Type Support
Object
, Array
, ArrayBuffer
, DataView
, Float32Array
, Float64Array
, Int8Array
, Int16Array
, Int32Array
, Uint8Array
, Uint8ClampedArray
, Uint16Array
, Uint32Array
, arguments
, Boolean
, Date
, Error
, Function
, Infinity
, Map
, NaN
, null
, Number
, RegExp
, Set
, String
, Symbol
, undefined
, WeakMap
, WeakSet
API
console;console;
Options:
callToJSON
Type:boolean
, default:true
CalltoJSON()
on passed object.indent
Type:number
, default:2
Number of spaces for indentation.maxDepth
Type:number
, default:Infinity
Print only this number of levels.min
Type:boolean
, default:false
Print without whitespace.plugins
Type:array
, default:[]
Plugins (see the next section).printFunctionName
Type:boolean
, default:true
Print function names or just[Function]
.escapeRegex
Type:boolean
, default:false
Escape special characters in regular expressions.highlight
Type:boolean
, default:false
Highlight syntax for terminal (works only withReactTestComponent
andReactElement
plugins.theme
Type:object
, default:{tag: 'cyan', content: 'reset'...}
Syntax highlight theme.
Uses ansi-styles colors +reset
for no color.
Available types:tag
,content
,prop
andvalue
.
Plugins
Pretty format also supports adding plugins:
var fooPlugin = { return val && val; } { return 'Foo: ' + ; }; var obj = foo: bar: {} ; ;// Foo: Object {// "bar": Object {}// }
ReactTestComponent
and ReactElement
plugins
var prettyFormat = ;var reactTestPlugin = ;var reactElementPlugin = ; var React = ;var renderer = ; var jsx = React; ;// <h1>// Hello World// </h1>