decoders
Advanced tools
Changelog
[2.4.0] - 2024-01-21
New features:
.pipe()
method on Decoder
allows you to pass the output of one decoder into
another:
string
.transform((s) => s.split(',')) // transform first...
.pipe(array(nonEmptyString)); // ...then validate that result
This was previously possible already with .then
, but it wasn't as elegant to express..pipe()
can also dynamically select another decoder, based on the input:
string
.transform((s) => s.split(',').map(Number)) // transform first...
.pipe((tup) =>
tup.length === 2
? point2d
: tup.length === 3
? point3d
: never('Invalid coordinate'),
);
"Value at key \"foo\": Must be \"bar\", \"qux\"" // ❌ Previously
"Value at key 'foo': Must be 'bar', 'qux'" // ✅ Now
New decoders:
Removed decoders:
numericBoolean
decoder, which was deprecated since 2.3.0.Changelog
[2.3.0] - 2024-01-09
New features:
enum
types are now supported (docs)record(values)
and record(keys, values)
forms
(docs)datelike
decoder (docs)bigint
(docs)constant()
and oneOf()
New decoders:
enum_
(see docs)record()
(see docs)select()
(see docs)bigint
(see docs)datelike
(see docs)decimal
(see docs)hexadecimal
(see docs)numeric
(see docs)Renamed decoders:
Some decoders have been renamed because their names were based on Flowisms. Names have been updated to better reflect TypeScript terminology:
dict()
→ record()
maybe()
→ nullish()
set()
→ setFromArray()
(to make room for a better set()
decoder in a future
version)Deprecated decoders:
The following decoders are deprecated because they were not commonly used, and a bit too specific to be in the standard library. They are also scheduled for removal in a future decoders version.
dict()
(prefer record()
)hardcoded()
(prefer always()
)maybe()
(prefer nullish()
)mixed
(prefer unknown
)numericBoolean()
Other changes:
positiveNumber
and positiveInteger
no longer accept -0
as valid inputseither
return type would sometimes get inferred incorrectly if members partially
overlapped (see #941)Changelog
[2.2.0]
Breaking change: Dropped Flow support*.
Breaking change: Projects that are not yet using strict: true
in their
tsconfig.json
files files are no longer supported. Previously, decoders went to great
lenghts to support both configurations, but the internal typing magic was getting too
complex to maintain without much benefit.
Breaking change: A small breaking change is introduced that removes the need for some packaging workarounds to support projects using old TypeScript/Node versions. It’s now simpler to use, and simpler to maintain:
-import { formatInline, formatShort } from 'decoders/format'; // ❌
+import { formatInline, formatShort } from 'decoders'; // ✅
-import { Result, ok, err } from 'decoders/result'; // ❌
+import { Result, ok, err } from 'decoders'; // ✅
Other, smaller changes, mostly internal:
strict
mode.(*: I'm still open to bundling Flow types within this package, but only if that can be
supported in a maintenance-free way, for example by using a script that will generate
*.flow
files from TypeScript source files. If someone can add support for that, I'm open
to pull requests! 🙏 )