The object to be converted to a diagnostic string value
Optional
format: number | booleanIdentifies whether the JSON value should be formated
true
- Format with 4 spacesfalse
(or not Truthy) - Do not formatA string representation of the object suitable for diagnostics logging
let obj = { a: 1, b: "Hello", c: { d: 2, e: "Darkness" } };
let objStr = dumpObj(obj);
// objStr === "[object Object]: { a: 1, b: "Hello", c: { d: 2, e: "Darkness" } }"
let objStrFmt = dumpObj(obj, true);
// objStrFmt === "[object Object]: {\n a: 1,\n b: "Hello",\n c: {\n d: 2,\n e: "Darkness"\n }\n}"
let objStrFmt2 = dumpObj(obj, 2);
// objStrFmt2 === "[object Object]: {\n a: 1,\n b: "Hello",\n c: {\n d: 2,\n e: "Darkness"\n }\n}"
let objStrFmt3 = dumpObj(obj, 0);
// objStrFmt3 === "[object Object]: { a: 1, b: "Hello", c: { d: 2, e: "Darkness" } }"
let objStrFmt4 = dumpObj(obj, false);
// objStrFmt4 === "[object Object]: { a: 1, b: "Hello", c: { d: 2, e: "Darkness" } }"
let objStrFmt5 = dumpObj(obj, null);
// objStrFmt5 === "[object Object]: { a: 1, b: "Hello", c: { d: 2, e: "Darkness" } }"
let objStrFmt6 = dumpObj(obj, undefined);
// objStrFmt6 === "[object Object]: { a: 1, b: "Hello", c: { d: 2, e: "Darkness" } }"
let objStrFmt7 = dumpObj(obj, "");
// objStrFmt7 === "[object Object]: { a: 1, b: "Hello", c: { d: 2, e: "Darkness" } }"
let err = new Error("Hello Darkness");
let errStr = dumpObj(err);
// errStr === "[object Error]: { stack: 'Error: Hello Darkness\n at <anonymous>:1:13', message: 'Hello Darkness', name: 'Error'"
let errStrFmt = dumpObj(err, true);
// errStrFmt === "[object Error]: {\n stack: "Error: Hello Darkness\n at <anonymous>:1:13",\n message: "Hello Darkness",\n name: "Error"\n}"
let errStrFmt2 = dumpObj(err, 2);
// errStrFmt2 === "[object Error]: {\n stack: "Error: Hello Darkness\n at <anonymous>:1:13",\n message: "Hello Darkness",\n name: "Error"\n}"
let errStrFmt3 = dumpObj(err, 0);
// errStrFmt3 === "[object Error]: { stack: "Error: Hello Darkness\n at <anonymous>:1:13", message: "Hello Darkness", name: "Error" }"
Returns string representation of an object suitable for diagnostics logging.