Function coerceAnyJson

  • Narrows an unknown value to an AnyJson if it is type-compatible*, or returns undefined otherwise.

    * This is not a 100% safe operation -- it will not deeply validate plain object or array structures to ensure that they contain only AnyJson values. When type-narrowing potential objects or arrays with this function, it's the responsibility of the caller to understand the risks of making such a shallow type assertion over the value data.

    Parameters

    • value: unknown

      The value to test.

    Returns Optional<AnyJson>

  • Narrows an unknown value to an AnyJson if it is type-compatible, or returns the provided default otherwise.

    Parameters

    • value: unknown

      The value to test.

    • defaultValue: AnyJson

      The default to return if value was undefined or of the incorrect type.

    Returns AnyJson