Function stringify

  • A safe method to JSON.stringify a value, useful for debugging and logging purposes.


    Without modifications, JSON.stringify has several shortcomings in debugging and logging usage:

    • throws when serializing anything containing a bigint
    • Uint8Arrays are often encoded in base 10 with newlines between each index item
    • functions and symbols are not clearly marked

    This method is more helpful in these cases:

    • bigint: 0n<bigint: 0n>
    • Uint8Array: Uint8Array.of(0,0)<Uint8Array: 0x0000>
    • function: (x) => x * 2<function: (x) => x * 2>
    • symbol: Symbol(A)<symbol: Symbol(A)>


    • value: any

      the data to stringify

    • spacing: number = defaultStringifySpacing

      the number of spaces to use in

    Returns string

Generated using TypeDoc