@ekim088/toolkit
    Preparing search index...

    Function safeJsonParse

    • Safely parses a JSON string into a typed value. On parse error, returns the provided fallback, the result of the provided error callback, or null.

      Type Parameters

      • T = unknown

      Parameters

      • jsonStr: string

        The JSON string to parse.

      Returns T | null

      The parsed value; on error, the fallback, the callback's result, or null when neither is given.

    • Safely parses a JSON string into a typed value. On parse error, returns the provided fallback, the result of the provided error callback, or null.

      Type Parameters

      • T = unknown

      Parameters

      • jsonStr: string

        The JSON string to parse.

      • errorCallback: (errantStr: string) => T

      Returns T

      The parsed value; on error, the fallback, the callback's result, or null when neither is given.

    • Safely parses a JSON string into a typed value. On parse error, returns the provided fallback, the result of the provided error callback, or null.

      Type Parameters

      • T = unknown

      Parameters

      • jsonStr: string

        The JSON string to parse.

      • fallback: T

      Returns T

      The parsed value; on error, the fallback, the callback's result, or null when neither is given.