DecodeResult
it's an either type, aunion type of two possible constructors.
It can either be:
DecodeSuccess
: a decoder was able to successfully decode a valueDecodeFailure
: a decoder failed to decode a valueA DecodeResult
brings three type parameters like in <a href="classes/decoder.html">Decoder</a>
:
In
: The input stream for a decoder.Out
: The expected result from a decoder.Err
: The type that contains information on why a decoder failed.Type signature for a function that takes an input and decodes it into a result object.
Extracts the Err
type from a Decoder
type.
Extracts the Int
type from a Decoder
type.
Given a type for an object T
and an array U
of field names from U
,
return a new object type with the specified fields U
marked as optional.
Extracts the Out
type from a Decoder
type.
Type alias for a decoder specialized in consuming values of type <a href="interfaces/textinput.html">TextInput</a>
and generate errors of type <a href="globals.html#decodeerror">DecodeError</a>
.
Transform a tuple type into the union of all the types in the tuple.
Type alias for a decoder specialized in consuming values of type <a href="interfaces/valueinput.html">ValueInput</a>
and generate errors of type <a href="globals.html#decodeerror">DecodeError</a>
.
Decoder that matches an array. Element values are not decoded and are typed
as any
.
Decoder that always retun the input value as an untyped (any
) value.
Decoder that matches a boolean value.
Decoder that matches one single character. This decoder will only fail if it
encounters the EOI
(end of input).
A decoder that doesn't consume any input but does return the current path position as its result value.
Match a single digit character.
A decoder that doesn't consume anything from the TextInput
and produces
undefined
if it matches the end of the input.
Decoder that matches a finite-number value.
Decoder that matches an integer value.
Pattern to recognize if a field name is in a format that doesn't require quotes.
Match any alphabetical character in a case insensitive matter.
Match any alphabetical lower-ccase-character.
Decoder that matches a null
value.
Decoder that matches a numeric value.
Match an optional whitespace character. If no whitespace is matched, the result
is the empty string ""
.
A decoder that produces all the remaining characters in TextInput
.
Decoder that matches a safe-integer value.
Decoder that matches a string value.
Decoder that validates a value to be an object.
Decoder that matches an undefined
value.
Match any alphabetical upper-case-character.
Match a single whitespace character.
A decoder that doesn't consume any portion of the string but does return the current index position as its result value.
Create a decoder that matches an array. Each element is decoded applying
the passed decoder
argument.
Adds double quotes to a string if it is not a simple sequence of alpha-numeric characters.
Utility function to generate a comma separate list of values where the last
one is concatenated by or
.
Helper function that return a function to decode from an input
of type string
to a DecodeResult
.
The function takes a TextDecoder
as the only argument.
This convenience function exists because TextDecoder
requires an input of
type TextInput and not string
.
Helper function that return a function to decode from an input
of type any
to a DecodeResult
.
The function takes a ValueDecoder
as the only argument.
This convenience function exists because ValueDecoder
requires an input of
type ValueInput and not just any
.
Match a sequence of digit characters. It expects at least one occurance.
The boundaries min
and max
are both inclusive and optional.
Make Entity
into english words accounting for pluralization by using qt
.
Returns a decoder that always fails with the given error.
Helper function to create an instance of DecodeResult
from a failed decoding.
Pretty prints a DecodeFailure<TextInput, Out, DecodeError>
.
Pretty prints a DecodeFailure<ValueInput, Out, DecodeError>
.
Pretty prints a DecodeFailure<TextInput, Out, DecodeError>
.
Pretty prints a DecodeFailure<ValueInput, Out, DecodeError>
.
Often time decoders are defined recursively. The language and type-system
do not allow for recursion. To work around that limit you create a lazy
decoder that wraps the desired decoder into a lazy function.
The decoder function f
is only invoked once and its result is reused
mutliple times if needed.
Match a sequence of case-insensitve alphabetical characters. It expects at
least one occurance. The boundaries min
and max
are both inclusive and
optional.
Decoder that matches exactly a specified literal value of type T
.
By default this function uses strict equality. If that is not the desired behavior, an equality function can be provided.
Match a sequence of lower-case alphabetical characters. It expects at least
one occurance. The boundaries min
and max
are both inclusive and optional.
Utility function to generate a decoder of type <a href="globals.html#valuedecoder">ValueDecoder</a>
from a function f
.
Utility function to generate a decoder of type <a href="globals.html#valuedecoder">ValueDecoder</a>
from a function f
.
Utility function to generate a decoder of type <a href="globals.html#valuedecoder">ValueDecoder</a>
from a function f
.
Utility function to generate a decoder of type <a href="globals.html#valuedecoder">ValueDecoder</a>
from a function f
.
Create a decoder that consume and produces an exact string match.
Match any single char from a list of possible values anyOf
.
Match exactly one char given its char code value as a number
.
Match exactly one char given its char code value as a number
.
Same as match but case-insensitive.
Match any single char that is not included in the list of possible values noneOf
.
Transform a decoder into one that consumes either the value from the passed decoder
or null
.
Create a decoder to validate objects.
Each field in the passed object argument fieldDecoders
is a distinct decoder
for a matching field in the input object.
The second argument optionalFields
, marks the fields to consider optionals.
Given an array of decoders, it traverses them all until one succeeds or they all fail.
Transform a decoder into one that consumes either the value from the passed decoder,
null
or undefined
.
Pretty prints a ValueInput.path
value.
Decodes an object applying a decoder for the keys and one for values of each field pair.
Generate a TextDecoder
that uses a RegExp
pattern to match a result.
By default, this decoder will capture the first group (group 0) returned from
the regular expression. This can be changed by providing a different value to
group
.
If the JS runtime you are working with allows it, it is suggested to use the
stycky modifier y
. Its main advantage is that it doesn't need to reallocate
a substring of the original input to perform its matching.
Given an array of decoders it tries to apply them all in sequence.
If they all succeed it returns a typed n
tuple where each element type
matches the expected type of the corresponding decoder.
Same as {@link recodValue} enforcing string keys.
Returns a decoder that always succeeds with the given result. The decoder doesn't consume anything from the input.
Helper function to create an instance of DecodeResult
from a succeeded decoding.
Same as takeCharWhile but with a minimum (min
) and maximum (max
)
constraints. They are both inclusive and mandatory.
Take a sequence of char that all satisfy the predicate f
. It works much like
testChar but for a sequence of charecters. The default is that the
decoder should match at least one result. That can be changed by passing
the second optional argument atLeast
with a different value.
Produces a decoder similar to {@link char} but the char is tested through
the predicate function f
. The character value is produced only if the predicate
succeeds.
Given a type in string
format, it checks that the current input
matches it
using typeof
.
It expects an input of type T
to pass the check made by the predicate
function f
. Notice that testValue doesn't (cannot) check that the input
is really of type T
. Such check must be performed by predicate itself.
It creates a tuple decoder by passing any number of decoders.
The number of expected elements in the tuple must match the number of provided decoders.
Transform a decoder into one that consumes either the value from the passed decoder
or undefined
.
Match a sequence of upper-case alphabetical characters. It expects at least
one occurance. The boundaries min
and max
are both inclusive and optional.
Tries to convert any value into a human readable string.
Static object that contains utility functions to generate any of the existing
decoding errors typed as DecodeError
instances.
Generate an instance of <a href="classes/customerror.html">CustomError</a>
.
Generate an instance of <a href="classes/unexpectedeoi.html">UnexpectedEoi</a>
.
Generate an instance of <a href="classes/customerror.html">CustomError</a>
.
Generate an instance of <a href="classes/expectedanyof.html">ExpectedAnyOf</a>
.
Generate an instance of <a href="classes/expectedatleast.html">ExpectedAtLeast</a>
.
Generate an instance of <a href="classes/expectedfield.html">ExpectedField</a>
.
Generate an instance of <a href="classes/expectedmatch.html">ExpectedMatch</a>
.
Generate an instance of <a href="classes/expectednoneof.html">ExpectedNoneOf</a>
.
Generate an instance of <a href="classes/expectedonce.html">ExpectedOnce</a>
.
Generate an instance of <a href="classes/expectedwithinrange.html">ExpectedWithinRange</a>
.
Generate an instance of <a href="classes/patternmismatch.html">PatternMismatch</a>
.
Union type of all possible decoding errors.