Socket
Socket
Sign inDemoInstall

decoders

Package Overview
Dependencies
0
Maintainers
1
Versions
134
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install
2345
14Next

2.4.0

Diff

Changelog

Source

[2.4.0] - 2024-01-21

New features:

  • A new .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.
  • The new .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'),
      );
    
  • Decoder error messages will now quote identifiers using single quotes, which makes them more human-readable in JSON responses. Compare:
    "Value at key \"foo\": Must be \"bar\", \"qux\""  // ❌ Previously
    "Value at key 'foo': Must be 'bar', 'qux'"        // ✅ Now
    
  • Some runtime perf optimizations

New decoders:

  • identifier (docs)
  • nanoid() (docs)

Removed decoders:

  • Remove numericBoolean decoder, which was deprecated since 2.3.0.
nvie
published 2.3.0 •

Changelog

Source

[2.3.0] - 2024-01-09

New features:

  • All enum types are now supported (docs)
  • Record decoder now supports both record(values) and record(keys, values) forms (docs)
  • Add datelike decoder (docs)
  • Add support for bigint (docs)
  • Add built-in support for common string validations
  • Better support for symbols in constant() and oneOf()

New decoders:

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:

  • Fix: positiveNumber and positiveInteger no longer accept -0 as valid inputs
  • Fix: either return type would sometimes get inferred incorrectly if members partially overlapped (see #941)
  • Reorganized internal module structure
  • Simplified some of the more complicated internal types
nvie
published 2.3.0-beta.3 •

nvie
published 2.3.0-beta.2 •

nvie
published 2.3.0-beta.1 •

nvie
published 2.3.0-test3 •

nvie
published 2.3.0-test2 •

nvie
published 2.3.0-test1 •

nvie
published 2.3.0-test4 •

nvie
published 2.2.0 •

Changelog

Source

[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:

  • Rewritten source code in TypeScript (previously Flow)
  • Rewritten test suite in Vitest (previously Jest)
  • Modern ESM and CJS dual exports (fully tree-shakable when using ESM)
  • Further reduced bundle size
  • Related, greatly simplified complex internal typing magic to make it work in projects with and without 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! 🙏 )

2345
14Next
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc