# decoders

> Elegant and battle-tested validation library for type-safe input data for TypeScript

Latest version **2.11.0** (published 2026-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install decoders
pnpm add decoders
yarn add decoders
bun add decoders
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.11.0 |
| Published | 2026-09-23 |
| First published | 2017-06-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 123.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 447 |
| Author | Vincent Driessen |
| Maintainers | nvie |
| Keywords | Decoder, decoders, typescript, runtime, input, schema, validation, type, inference, verify |

## Links

- npm: https://www.npmjs.com/package/decoders
- Repository: https://github.com/nvie/decoders
- Homepage: https://github.com/nvie/decoders#readme
- Issues: https://github.com/nvie/decoders/issues
- npm.io page: https://npm.io/package/decoders

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 2.11.0 (latest) — 2026-09-23
- 2.9.0-pre.5 (pre) — 2026-03-06
- 2.8.0-1 (beta) — 2025-09-24
- 2.10.1 — 2026-09-14
- 2.10.0 — 2026-09-14
- 2.9.3 — 2026-04-07
- 2.9.2 — 2026-03-30
- 2.9.1 — 2026-03-11
- 2.9.0 — 2026-03-08
- 2.9.0-pre.4 — 2026-03-04
- 2.9.0-pre.3 — 2026-03-04
- 2.9.0-pre.2 — 2026-03-03
- 2.9.0-pre.1 — 2026-03-02
- 2.9.1-pre.0 — 2026-03-02
- 2.9.0-pre.0 — 2026-03-02
- … 147 more at https://npm.io/package/decoders/versions

## README

<img alt="Decoders logo" src="./assets/logo@2x.png" style="width: 100%; max-width: 830px; max-height: 248px" width="830" /><br />

[![npm](https://img.shields.io/npm/v/decoders.svg)](https://www.npmjs.com/package/decoders)
[![Test Status](https://github.com/nvie/decoders/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/nvie/decoders/actions)
[![Bundle size](https://deno.bundlejs.com/badge?q=decoders@2.9.0&treeshake=[{number,object,optional,string}])](https://bundlejs.com/?q=decoders%402.9.0&treeshake=%5B%7B+number%2Cobject%2Coptional%2Cstring+%7D%5D)

Elegant and battle-tested validation library for type-safe input data for TypeScript.

## Basic example

```typescript
import { array, isoDate, number, object, optional, string } from 'decoders';

// Incoming data at runtime, e.g. the request body
// The point is that this data is untrusted and its type unknown
const externalData = {
  id: 123,
  name: 'Alison Roberts',
  createdAt: '2026-01-11T12:26:37.024Z',
  tags: ['foo', 'bar'],
};

// Write the decoder (= what you expect the data to look like)
const userDecoder = object({
  id: number,
  name: string,
  createdAt: optional(isoDate),
  tags: array(string),
});

// Call .verify() on the incoming data
const user = userDecoder.verify(externalData);
//    ^^^^
//    TypeScript will infer this type as:
//    {
//      id: number;
//      name: string;
//      createdAt?: Date;
//      tags: string[];
//    }
```

## Installation

```bash
npm install decoders
```

## Requirements

You must set `strict: true` in your `tsconfig.json` in order for type inference to work
correctly!

```js
// tsconfig.json
{
  "compilerOptions": {
    "strict": true
  }
}
```

## Documentation

Documentation can be found on [decoders.cc](https://decoders.cc).

There is a dedicated page that explains how to
[build your own decoders](https://decoders.cc/docs/building-your-own).

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