Skip to content

v2.0.0

Compare
Choose a tag to compare
@nvie nvie released this 08 Feb 14:10
· 133 commits to main since this release

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 πŸ› οΈ

Bundle size comparison between v1 and v2

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 eithers

Implementation changes:

  • Major reorganization of internal module structure
  • Various simplification of internals