• Returns string representation of an object suitable for diagnostics logging.

    Parameters

    • object: any

      The object to be converted to a diagnostic string value

    • Optionalformat: number | boolean

      Identifies whether the JSON value should be formated

      • true - Format with 4 spaces
      • 'number' - The number of spaces to format with
      • false (or not Truthy) - Do not format

    Returns string

    A 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" }"