PrettyFormat
Pretty format any javascript object.
Handles the following types:
- null
- undefined
- Number
- Boolean
- String
- Array
- Map
- Set
- Function
- Class (detected as a Function, so pretty formatted just like a function)
- Object
Example:
Without indentation
new PrettyFormat([1, 2]).toString();
With indentation (indent by 2 spaces)
new PrettyFormat([1, 2]).toString(2);
Simple examples
new PrettyFormat(true).toString() === 'true';
new PrettyFormat(null).toString() === 'null';
new PrettyFormat([1, 2]).toString() === '[1, 2]';
new PrettyFormat({name: "John", age: 29}).toString() === '{"age": 29, "name": John}';
Complex example
let map = new Map();
map.set('a', [10, 20]);
map.set('b', [30, 40, 50]);
function testFunction() {}
let obj = {
theMap: map,
aSet: new Set(['one', 'two']),
theFunction: testFunction
};
const prettyFormatted = new PrettyFormat(obj).toString(2);
Constructor Summary
Public Constructor | ||
public |
constructor(obj: *) |
Method Summary
Public Methods | ||
public |
Get the results as a string, optionally indented. |
Public Constructors
public constructor(obj: *) source
Params:
Name | Type | Attribute | Description |
obj | * |