0.6.0 • Published 7 years ago

verus v0.6.0

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

Verus - Object schema validator

TypeScript is cool, but its typesystem can't protect against invalid external data, like REST-API responses. You can write validators, but to get the benefits of static typing you would have to also write interface definitions.

Verus is a TypeScript (and Javascript) library that can do both at the same time!

Example:

import { String, Shape, ISODate, ArrayOf, typeValue } from 'verus'

// typeof User = { name: string, birthdate: Date, employment: 'employee'|'worker'|'self-employed', email: string, kids: string[] }
export class User extends Shape({
    name: String,
    birthdate: ISODate,
    email: String,
    employment: Union('employee', 'worker', 'self-employed')
    kids: ArrayOf(String)
}) {}

const userJson = {
    name: 'Joan Smith',
    birthdate: '1986-11-05T14:30-02:00',
    email: 'joan.smith@protonmail.ch',
    employment: 'employee'
    kids: ['Jack', 'Jill']
}

const validation = User.validate(userJson)
if (validation.result === 'valid') {
    doStuffWithUser(validation.value)
}
0.6.0

7 years ago

0.5.0

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago