0.0.4 • Published 6 years ago

ts-runtime-check v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Example

import 'reflect-metadata';
import { BaseValidator, Check, CheckedObject, Type, Validator } from 'ts-runtime-check';

const ColorValidator: Validator = (value, options) =>
	(typeof value === 'string' && /^#(?:[0-9a-f]{3}){1,2}$/i.test(value)) || BaseValidator(value, options);

export default class User extends CheckedObject<User> {
	@Check() id: number;
	@Check() name: string;
	@Check(Type.Array.of(ColorValidator)) colors: string[];
}

console.log(User.fromPlainObject({ id: 1, name: 'foo', colors: ['#ff0000'] }));
console.log(User.fromPlainObject({ id: 2, name: 1337 }));  // TypeError
0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago