Options
All
  • Public
  • Public/Protected
  • All
Menu

A Decoder represents a value that can be converted to a known type, either from JSON or from an typed object.

Type parameters

  • A

Hierarchy

  • Decoder

Index

Constructors

constructor

Properties

Private fn

fn: DecoderFn<A>

Methods

andThen

  • andThen<B>(f: function): Decoder<B>
  • Chains decoders together. Can be used when the value from a decoder is needed to decode the rest of the data. For example, if you have a versioned api, you can check the version number and then select an appropriate decoder for the rest of the data.

    Also, chaining decoders is one way to build new types from decoded objects.

    Type parameters

    • B

    Parameters

    Returns Decoder<B>

assign

  • assign<K, B>(k: K, other: Decoder<B> | function): Decoder<A & object>

decodeAny

  • decodeAny(value: any): Result<string, A>
  • Run the current decoder on any value

    Parameters

    • value: any

    Returns Result<string, A>

decodeJson

  • decodeJson(json: string): Result<string, A>
  • Parse the json string and run the current decoder on the resulting value. Parse errors are returned in an Result.Err, as with any decoder error.

    Parameters

    • json: string

    Returns Result<string, A>

do

  • Inject a side-effectual operation in the middle of a Decoder chain. This is a convenient mechanism for debugging decoders using console logging. I don't reccomend using this mechanusm for making API calls, or anything complex like that.

    Parameters

    • fn: function
        • (a: A): void
        • Parameters

          • a: A

          Returns void

    Returns Decoder<A>

elseDo

  • If a decoder fails, do something side-effectual

    Parameters

    • f: function
        • (e: string): void
        • Parameters

          • e: string

          Returns void

    Returns Decoder<A>

map

  • Lifts any function up to operate on the value in the Decoder context.

    Type parameters

    • B

    Parameters

    • f: function
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    Returns Decoder<B>

mapError

  • mapError(f: function): Decoder<A>
  • If a decoder fails, map over the failure message.

    Parameters

    • f: function
        • (e: string): string
        • Parameters

          • e: string

          Returns string

    Returns Decoder<A>

orElse

  • If a decoder fails, use an alternative decoder.

    Parameters

    • f: function

    Returns Decoder<A>

toAnyFn

  • toAnyFn(): function
  • Returns a function that runs this docoder over any value when called. This is a convenient way to convert a decoder into a callback.

    Returns function

      • (value: any): Result<string, A>
      • Parameters

        • value: any

        Returns Result<string, A>

toJsonFn

  • toJsonFn(): function
  • Returns a function that runs this decoder over a JSON string when called. This is a convenient way to convert a decoder into a callback.

    Returns function

      • (json: string): Result<string, A>
      • Parameters

        • json: string

        Returns Result<string, A>

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc