gcanti / io-ts-types

A collection of codecs and combinators for use with io-ts
https://gcanti.github.io/io-ts-types/
MIT License
311 stars 40 forks source link

Validation Combinators (using `Decoder`) #168

Open anthonyjoeseph opened 2 years ago

anthonyjoeseph commented 2 years ago

🚀 Feature request

yup, joi, zod, superstruct, ajv, and validate.js all have a big library of combinators for the sake of validation

io-ts is a 'runtime type system' This PR is meant to expand it into a 'runtime validation' system

Using 'decoders' b/c they compose

Current Behavior

Validation combinators must be implemented manually

Desired Behavior

An extensive, verbose & granular library of common validators

Suggested Solution

By type:

partial implementation (playground)

The decoders & combinators are split into four categories:

Hopefully, enough implementation is specified to understand the intent

If I made a PR of this or some subset of it, would you consider it?

Who does this impact? Who is this for?

Users looking for a runtime validation library

Describe alternatives you've considered

A fork of this library, or maybe new one entirely? io-ts-validations? io-ts-decoders?

Maybe the decoders that are simply 'maps', with no chance of failure (e.g. string.truncate) could purely live in Util, since they're trivial to implement as Decoders?

Additional context

closes https://github.com/gcanti/io-ts-types/issues/151 closes https://github.com/gcanti/io-ts-types/issues/59

Your environment

Software Version(s)
fp-ts 2.11.8
io-ts 2.2+
io-ts-types N / A
TypeScript 3.5.0+