# io-ts-reporters

> Formatting of io-ts validation errors

Latest version **2.0.1** (published 2022-02-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install io-ts-reporters
pnpm add io-ts-reporters
yarn add io-ts-reporters
bun add io-ts-reporters
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-02-07 |
| First published | 2017-04-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 90 |
| Maintainers | oliverjash, gillchristian |
| Keywords | typescript, runtime, decoder, encoder, schema |

## Links

- npm: https://www.npmjs.com/package/io-ts-reporters
- Repository: https://github.com/gillchristian/io-ts-reporters
- Issues: https://github.com/gillchristian/io-ts-reporters/issues
- npm.io page: https://npm.io/package/io-ts-reporters

## Dependencies (1)

- [@scarf/scarf](https://npm.io/package/@scarf/scarf.md) ^1.1.1

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2022-02-07
- 2.0.0 — 2021-07-14
- 2.0.0-rc1 — 2021-07-14
- 1.2.2 — 2020-07-21
- 1.2.1 — 2020-07-15
- 1.2.0 — 2020-06-25
- 1.1.0 — 2020-06-10
- 1.0.0 — 2019-07-26
- 0.0.21 — 2018-08-11
- 0.0.20 — 2018-02-17
- 0.0.19 — 2018-02-17
- 0.0.18 — 2018-01-29
- 0.0.17 — 2017-11-10
- 0.0.16 — 2017-09-23
- 0.0.15 — 2017-07-28
- … 12 more at https://npm.io/package/io-ts-reporters/versions

## README

# io-ts-reporters

[Error reporters](https://github.com/gcanti/io-ts#error-reporters) for
[io-ts](https://github.com/gcanti/io-ts).

![scarf-downloads](https://scarf.sh/package/installs-badge/376fab85-f2aa-4e85-9225-3be51d9534fc)

Currently this package only includes one reporter. The output is an array of
strings in the format of:

```
Expecting ${expectedType} at ${path} but instead got: ${actualValue}
```

And for union types:

```
Expecting one of:
    ${unionType1}
    ${unionType2}
    ${...}
    ${unionTypeN}
at ${path} but instead got: ${actualValue}
```

## Installation

```bash
yarn add io-ts-reporters
```

## Example

```ts
import * as t from 'io-ts'
import reporter from 'io-ts-reporters'

const User = t.interface({name: t.string})

// When decoding fails, the errors are reported
reporter.report(User.decode({nam: 'Jane'}))
//=> ['Expecting string at name but instead got: undefined']

// Nothing gets reported on success
reporter.report(User.decode({name: 'Jane'}))
//=> []
```

To only format the validation errors in case the validation failed (ie.
`mapLeft`) use `formatValidationErrors` instead.

```ts
import * as t from 'io-ts'
import {formatValidationErrors} from 'io-ts-reporters'
import * as E from 'fp-ts/Either'
import {pipe} from 'fp-ts/pipeable'

const User = t.interface({name: t.string})

const result = User.decode({nam: 'Jane'}) // Either<t.Errors, User>

E.mapLeft(formatValidationErrors)(result) // Either<string[], User>
```

For more examples see [the tests](./tests/index.test.ts).

## TypeScript compatibility

| io-ts-reporters version | required typescript version |
| ----------------------- | --------------------------- |
| 1.0.0                   | 3.5+                        |
| <= 0.0.21               | 2.7+                        |

## Testing

```bash
yarn
yarn run test
```

[io-ts]: https://github.com/gcanti/io-ts#error-reporters

## Credits

This library was created by [OliverJAsh](https://github.com/OliverJAsh).

---
_Source: https://npm.io/package/io-ts-reporters · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
