Create a decoder for arbitrary key/value pairs from a key decoder and a value decoder.
Effectively transforms a Decoder<K>
and a Decoder<V>
into a Decoder<Array<{ key: K, value: V }>>
.
Apply the provided decoder at the specified path in a complex object. Path can be either:
string
(when querying a top level field)number
(when querying an array index)Array<string | number>
(to query an arbitrarily nested field)Transform a Decoder<T>
into a Decoder<T | null>
.
Try all the given decoders and return the result of the first one not raising an error. If none succeed, throws a OneOfDecoderError
For example, this is how nullable is defined:
const nullable = <T>(decoder: Decoder<T>) => decod.oneOf(decoder, decod.null_);
Transform a Decoder<T>
into a Decoder<T | null | undefined>
.
Create a decoder for some complex structure from an object where each value is a Decoder
and the keys
correspond to the desired output structure.
const personDecoder = decod.props({
first_name: decod.at('first_name', decod.string),
last_name: decod.at('last_name', decod.string),
age: decod.at('age', decod.number),
});
Try a decoder, and fallback to a specified value (if provided) if the decoder fails.
If no default value is specified, fallback to undefined
.
Decode an unknown
value as a boolean
.
Otherwise, throws a ScalarDecoderError.
Decode an unknown
value as a Date
.
Otherwise, throws a ScalarDecoderError.
Decode an unknown
value if it matches the expected value.
Otherwise, throws a ScalarDecoderError.
It is mostly intended to be used in conjunction with oneOf for decoding groups of specific values.
const droidDecoder = decod.oneOf(
decod.is('r2d2'),
decod.is('c3po')
);
Decode an unknown
value as a null
value.
Otherwise, throws a ScalarDecoderError.
Decode an unknown
value as a number
.
Otherwise, throws a ScalarDecoderError.
Decode an unknown
value as a string
.
Otherwise, throws a ScalarDecoderError.
Decode an unknown
value as undefined
.
Otherwise, throws a ScalarDecoderError.
Generated using TypeDoc
Synonym for try_