Home Manual Reference Source
import PrettyFormat from 'ievv_jsbase/lib/utils/PrettyFormat'
public class | source

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

toString(indent: number): string

Get the results as a string, optionally indented.

Public Constructors

public constructor(obj: *) source

Params:

NameTypeAttributeDescription
obj *

Public Methods

public toString(indent: number): string source

Get the results as a string, optionally indented.

Params:

NameTypeAttributeDescription
indent number

The number of spaces to indent by. Only child objects are indented, and they are indented recursively.

Return:

string