ts-data-forge
    Preparing search index...

    Variable unknownToStringConst

    unknownToString: (
        value: unknown,
        options?: Partial<Readonly<{ prettyPrintObject: boolean }>>,
    ) => string

    Converts an unknown value to its string representation in a type-safe manner.

    This function handles all JavaScript types and provides consistent string conversion with proper error handling for edge cases like circular references. Unlike naive toString() calls, this function never throws and handles all value types gracefully.

    Type conversion rules:

    • Strings: returned as-is
    • Numbers, booleans, bigints: converted via toString()
    • Symbols: converted to their description string
    • Functions: converted to their string representation
    • null: returns "null" (not "null" from JSON)
    • undefined: returns "undefined"
    • Date: converted to ISO string
    • RegExp: converted to regex literal string
    • Map: converted to Map representation with entries
    • Set: converted to Set representation with values
    • Error: returns error message
    • Objects: JSON stringified (with optional pretty printing)

    Type Declaration

      • (
            value: unknown,
            options?: Partial<Readonly<{ prettyPrintObject: boolean }>>,
        ): string
      • Parameters

        • value: unknown

          The unknown value to convert to string

        • Optionaloptions: Partial<Readonly<{ prettyPrintObject: boolean }>>

          Optional configuration for the conversion

          • prettyPrintObject

            If true, objects are formatted with 2-space indentation

        Returns string

        The string representation of the value. For circular references or non-serializable objects, returns an error message string

        Error Handling: Circular references and non-serializable objects return descriptive error messages instead of throwing

    JSON.stringify - Underlying serialization for objects