https://github.com/cdaringe/runtypes-pretty-validation
runtypes pretty validation
https://github.com/cdaringe/runtypes-pretty-validation
Last synced: 4 months ago
JSON representation
runtypes pretty validation
- Host: GitHub
- URL: https://github.com/cdaringe/runtypes-pretty-validation
- Owner: cdaringe
- Created: 2023-01-20T23:06:52.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-31T22:39:21.000Z (almost 2 years ago)
- Last Synced: 2025-11-30T23:49:04.240Z (7 months ago)
- Language: TypeScript
- Size: 116 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: readme.md
- Contributing: .github/contributing.md
Awesome Lists containing this project
README
# runtypes-pretty-validation
validate [runtypes](https://github.com/pelotom/runtypes) schemas against a value, and reflect back a pretty validation report, matching the schema.
Prettyifies structural error messages arbitrarily deep.
```ts
import { validate } from "runtypes-pretty-validation";
const schema = rt.Record({ foo: rt.Literal("bar") });
validate(schema, null); // Expected object, got "null"
validate(schema, { bar: "bar" }); // { foo: 'Expected literal `bar`, but was `undefined`' }
validate(schema, { foo: "bar" }); // undefined, all valid
```
[](https://github.com/cdaringe/runtypes-pretty-validation/actions/workflows/main.yml)
## install
`npm install runtypes-pretty-validation`
## options
Options may be specified. See [./index.ts](./index.ts) for defaults.
```ts
validate(schema, value[, opts])
```
- `useFirstUnionSchemaOnFail: boolean`: if a validation fails all union members, report the schema validation errors from the first schema in the union.
## examples
see [test.ts](./test.ts) for more.