Class BigIntDecoder

Decoder for bigint.

Hierarchy

  • AbstractNumberDecoder<bigint>
    • BigIntDecoder

Properties

name: string = "bigint"

Methods

  • Parameters

    • arg: unknown

    Returns boolean

  • Parameters

    • num: unknown

    Returns num is number

  • An alias for transform.

    Type Parameters

    • U

    Parameters

    • tranformer: ((decoded) => U)

      transformer function

        • (decoded): U
        • Parameters

          • decoded: bigint

          Returns U

    Returns Decoder<U>

    a decoder of the transformed value

  • Takes a decoder of U and produces a decoder of the union of T | U.

    Useful for composing decoders that can decode many types.

    Example:

    asString.or(asNumber) // produces a decoder for string | number
    asString.or(asNumber).or(asBoolean)) // produces a decoder for string | number | boolean

    Type Parameters

    • U

    Parameters

    • other: Decoder<U>

      decoder for next type U

    Returns Decoder<bigint | U>

    A decoder for decoding T | U

  • Similar to decode, but throws an error if decoding fails.

    Parameters

    • arg: unknown

      value to decode

    Returns bigint

    decoded value

  • Parameters

    • num: unknown

    Returns boolean

  • Makes it possible to apply some transformation on a decoded value.

    const asInt = asNumber.transform(num => parseInt(num))
    asInt.parse(117.565) // produces 117

    Type Parameters

    • U

    Parameters

    • transformer: ((decoded) => U)

      transformer function

        • (decoded): U
        • Parameters

          • decoded: bigint

          Returns U

    Returns Decoder<U>

    a decoder of the transformed value

  • Applies an operation that can also fail to this decoder.

    const asInt = asNumber.try(num => {
    if (Number.isInteger(number)) return success(num)
    else return failure("expected integer but got " + num)
    })
    asInt.parse(117.565) // throws error - $root: expected integer but got 117.565

    Type Parameters

    • U

    Parameters

    Returns Decoder<U>

    a decoder

Generated using TypeDoc