# ts-runtime-validator

> A Typescript transformer that generates runtime validation functions from type definitions.

Latest version **0.0.6** (published 2021-10-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install ts-runtime-validator
pnpm add ts-runtime-validator
yarn add ts-runtime-validator
bun add ts-runtime-validator
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2021-10-31 |
| First published | 2021-05-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jrdrg |
| Maintainers | jrdrg |

## Links

- npm: https://www.npmjs.com/package/ts-runtime-validator
- npm.io page: https://npm.io/package/ts-runtime-validator

## Recent versions

- 0.0.6 (latest) — 2021-10-31
- 0.0.5 — 2021-05-28
- 0.0.4 — 2021-05-27
- 0.0.4-0 — 2021-05-27
- 0.0.3 — 2021-05-27
- 0.0.2 — 2021-05-27
- 0.0.1 — 2021-05-26

## README

# ts-runtime-validator

A Typescript transformer to generate runtime validation functions from type definitions.

```typescript
type Foo = {
  bar: string;
  baz: number | null;
};

const invalid = {
  bar: 123,
};

validateType<Foo>(invalid); // Not of type 'Foo', throws an exception

const valid: any = {
  bar: 'valid',
  baz: 1,
};

validateType<Foo>(valid); // Type guard, asserts that valid is Foo
console.log(valid.bar); // 'valid'

try {
  const input: any = { bar: 'a' };
  validateType<Foo>(input);
  console.log(input.baz);
} catch (e) {
  // Required field is missing: baz
}
```

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