decoders

Sets & Maps

Decoders for maps and sets.

mapping

mapping( decoder: Decoder<T> ): Decoder<Map<string, T>> (source)

Similar to record(), but returns the result as a Map<string, T> (an ES6 Map) instead.

Try it
mapping(number).verify({ red: 1, blue: 2, green: 3 })
InputResult

setFromArray

setFromArray( decoder: Decoder<T> ): Decoder<Set<T>> (source)

Similar to array(), but returns the result as an ES6 Set.

Try it
setFromArray(string).verify(['abc', 'pqr'])
InputResult

Limiting set sizes

sized( decoder: Decoder<Set<T>>, options: SizeOptions ): Decoder<Set<T>> (source)

Will be available once 2.9 is released.

Takes any set decoder and rejects values that don't match the given size constraints. Also works with strings and arrays.

SizeOptions accepts min, max, or size (shorthand for exact length).

Try it
sized(setFromArray(string), { min: 1, max: 3 }).verify(['a', 'b'])
InputResult

On this page