Releases: nvie/decoders
v2.0.1
-
TypeScript-only: Fix definition of JSONObject to reflect that its values might always be
undefined
as well. -
TypeScript-only: Changed return types of
{ [key: string]: T }
toRecord<string, T>
. -
TypeScript-only: Fine-tune the type of
instanceOf()
.
v2.0.0
This is a breaking change, which brings numerous benefits:
- A simpler API 😇
- Smaller bundle size (67% reduction 😱)
- Tree-shaking support 🍃
- Runtime speed 🏎️
- Better documentation 📚
- Better support for writing your own decoders 🛠️
Please see the migration guide for precise instructions on how to
adjust your v1 code.
The main change is the brand new Decoder<T>
API! The tl;dr is:
Replace this v1 pattern... | ...with this v2 API | Notes | |
---|---|---|---|
mydecoder(input) |
→ | mydecoder.decode(input) |
migration instructions |
guard(mydecoder)(input) |
→ | mydecoder.verify(input) |
migration instructions |
map(mydecoder, ...) |
→ | mydecoder.transform(...) |
migration instructions |
compose(mydecoder, predicate(...)) |
→ | mydecoder.refine(...) |
migration instructions |
describe(mydecoder, ...) |
→ | mydecoder.describe(...) |
|
mydecoder(input).value() |
→ | mydecoder.value(input) |
|
either , either3 , ..., either9 |
→ | either |
migration instructions |
tuple1 , tuple2 , ... tuple6 |
→ | tuple |
migration instructions |
dispatch |
→ | taggedUnion |
migration instructions |
url(...) |
→ | httpsUrl / url (signature has changed) |
migration instructions |
The full documentation is available on decoders.cc.
Other features:
- Include ES modules in published NPM builds (yay tree-shaking! 🍃)
- Much smaller total bundle size (67% smaller compared to v1 😱)
Other potentially breaking changes:
- Drop support for all Node versions below 12.x
- Drop support for TypeScript versions below 4.1.0
- Drop support for Flow versions below 0.142.0
- Drop all package dependencies
- Direct reliance on
lemons
has been removed
New decoders:
Other improvements:
optional()
,
nullable()
, and
maybe()
now each take an optional 2nd param to
specify a default value- Better error messages for nested
either
s
Implementation changes:
- Major reorganization of internal module structure
- Various simplification of internals
v2.0.0-beta13
Upgrading to v2 can, but doesn't have to be a breaking change for you. If upgrading causes errors for you, please see the migration guide for instructions.
v1.25.5
v1.25.4
- Expose
nonEmptyArray
function in TypeScript (Thanks, @mszczepanczyk!)