1.0.2 • Published 3 years ago

runval v1.0.2

Weekly downloads
6
License
ISC
Repository
-
Last release
3 years ago

runval

A typescript first runtime schema validation library.

This library is currently very unstable. It's probably not wise to use it (unless you want to test!)

Usage

import { boolean, number, object, string, Infer } from '../src';

const schema = object({
    string: string(),
    number: number(),
    nestedObject: object({
        anotherNumber: number(),
        boolean: boolean(),
    }),
});

type SchemaType = Infer<typeof schema>;

const data: any = { ... };

// type guard
if (schema.is(data)) {
    // data is typeof schema
}

// validate
const output = schema.validate(data);
if (output.success) {
    const validated = output.data;
}
else {
    throw output.error;
}
1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago