Skip to content

Releases: nvie/decoders

v1.16.1

14 Sep 14:46
Compare
Choose a tag to compare
  • Internal change to make the code Flow 0.105.x compatible. Basically stops using array spreads ([...things]) in favor of Array.from().

v1.16.0

10 Aug 21:53
Compare
Choose a tag to compare

New feature:

  • Allow map() calls to throw an exception in the mapper function to reject
    the decoder. Previously, these mapper functions were not expected to ever
    throw.

v1.15.0

27 Jun 07:24
Compare
Choose a tag to compare

New features:

  • Support constructors that have required arguments in instanceOf decoders in TypeScript (see #308, thanks @Jessidhia!)
  • Add support for type predicates in predicate() in TypeScript (see #310, thanks @Jessidhia!)

Fixes:

  • Add support for Flow >= 0.101.0

v1.14.0

28 May 09:12
Compare
Choose a tag to compare

Potential breaking changes:

  • Stricten pojo criteria. Now, custom classes like new String() or new Error() will not be accepted as a plain old Javascript object (= pojo) anymore.

Fixes:

  • Add support for Flow 0.98+

v1.13.1

01 May 20:15
Compare
Choose a tag to compare

Fixes:

  • Don't reject URLs that contains commas (,)

v1.13.0

18 Mar 09:26
Compare
Choose a tag to compare

Potentially breaking changes:

  • Changed the API interface of dispatch(). The previous version was too complicated and was hardly used. The new version is easier to use in practice, and has better type inference support in TypeScript and Flow.

    Previous usage:

    const shape = dispatch(
        field('type', string),
        type => {
            switch (type) {
                case 'rect': return rectangle;
                case 'circle': return circle;
            }
            return fail('Must be a valid shape');
        }
    );
    

    New usage: docs

    const shape = dispatch('type', { rectangle, circle });
    

    Where rectangle and circle are decoders of which exactly one will be invoked.

  • Removed the field() decoder. It was not generic enough to stay part of the standard decoder library. (It was typically used in combination with dispatch(), which now isn't needed anymore, see above.)

  • pojo decoder now returns Decoder<{[string]: mixed}> instead of the unsafe Decoder<Object>.

Fixes and cleanup:

  • Internal reorganization of modules
  • Improve TypeScript support
    • Reorganization of TypeScript declarations
    • More robust test suite for TypeScript
    • 100% TypeScript test coverage

v1.12.0

13 Mar 12:59
Compare
Choose a tag to compare

New decoders:

  • oneOf(['foo', 'bar']) will return only values matching the given values
  • instanceOf(...) will return only values that are instances of the given class. For example: instanceOf(TypeError).

v1.11.1

19 Jan 09:14
Compare
Choose a tag to compare
  • Reduce bundle size for web builds
  • New build system
  • Cleaner package output

v1.11.0

05 Jan 09:47
Compare
Choose a tag to compare

Potentially breaking changes:

  • Decoders now all take mixed (TypeScript: unknown) arguments, instead of
    any 🎉 ! This ensures that the proper type refinements in the
    implementation of your decoder are made. (See migration notes below.)
  • Invalid dates (e.g. new Date('not a date')) won’t be considered valid by
    the date decoder anymore.

New features:

  • guard() now takes a config option to control how to format error
    messages. This is done via the guard(..., { style: 'inline' }) parameter.

    • 'inline': echoes back the input value and inlines errors (default);
    • 'simple': just returns the decoder errors. Useful for use in sensitive contexts.
  • Export $DecoderType utility type so it can be used outside of the decoders
    library.

Fixes:

  • Fixes for some TypeScript type definitions.
  • Add missing documentation.

Migration notes:

If your decoder code breaks after upgrading to 1.11.0, please take the
following measures to upgrade:

  1. If you wrote any custom decoders of this form yourself:

    const mydecoder = (blob: any) => ...
    //                       ^^^ Decoder function taking `any`

    You should now convert those to:

    const mydecoder = (blob: mixed) => ...
    //                       ^^^^^ Decoders should take `mixed` from now on

    Or, for TypeScript:

    const mydecoder = (blob: unknown) => ...
    //                       ^^^^^^^ `unknown` for TypeScript

    Then follow and fix type errors that pop up because you were making
    assumptions that are now caught by the type checker.

  2. If you wrote any decoders based on predicate(), you may have code like
    this:

    const mydecoder: Decoder<string> = predicate(
      s => s.startsWith('x'),
      'Must start with "x"'
    );

    You'll have to change the explicit Decoder type of those to take two type
    arguments:

    const mydecoder: Decoder<string, string> = predicate(
    //                               ^^^^^^ Provide the input type to predicate() decoders
      s => s.startsWith('x'),
      'Must start with "x"'
    );

    This now explicitly records that predicate() makes assumptions about its
    input type—previously this wasn’t get caught correctly.

v1.11.0-alpha2

02 Jan 11:59
Compare
Choose a tag to compare
v1.11.0-alpha2 Pre-release
Pre-release
v1.11.0-alpha2