ClementNerma / ts-validator

An extremely simple, strictly-typed data validator for TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ts-validator

NOTE: I encourage you to use https://github.com/colinhacks/zod instead.

Usage example:

import { arrayOf, json, number, string, struct } from 'ts-validator'

const schema = struct({
  username: string,
  password: string,
  age: number,
  tastes: arrayOf(string),
})

const value = json('{ "a": 2 }', schema)

if (value.ok) {
  value.data // Typed as: { username: string, password: string, age: number, tastes: string[] }
} else {
  value.error.message // string
}

About

An extremely simple, strictly-typed data validator for TypeScript

License:Apache License 2.0


Languages

Language:TypeScript 100.0%