This question is old, but I'd like to share my validation library also.
It's type-script friendly, tiny (no tons of unnecessary functionality) and easily extensible by custom validators.
npm: https://www.npmjs.com/package/checkeasy
github: https://github.com/smbwain/checkeasy
import {alternatives, arrayOf, int, object, oneOf, optional, string} from 'checkeasy';
const myValidator = object({
a: int({max: 5}),
b: string(),
c: optional(float()),
d: oneOf(['a', 'b', 7] as const),
e: alternatives([string(), int()]),
f: arrayOf(string()),
g: object({
subP: string(),
}),
});
const value = myValidator(anyUnsafeData, 'name');
// type of value is: {
// a: number,
// b: string,
// c: number | undefined,
// d: "a" | "b" | 7,
// e: string | number,
// f: string[],
// g: {subP: string},
//}
It also throws clear human readable messages in errors. E.g.
myValidator({a: 'hello'}, 'data');
// throws: [data.a] should be an integer
myValidator({a: 1, b: 'string', d: 'a', e: true}, 'data');
// throws: All alternatives failed for [data.e]:
// [data.e.@alternative(0)] should be a string
// [data.e.@alternative(1)] should be an integer