Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/d-fischer/ts-runtime-check
Check the types of your external objects with (mostly) just TypeScript types.
https://github.com/d-fischer/ts-runtime-check
Last synced: about 22 hours ago
JSON representation
Check the types of your external objects with (mostly) just TypeScript types.
- Host: GitHub
- URL: https://github.com/d-fischer/ts-runtime-check
- Owner: d-fischer
- License: mit
- Created: 2018-09-12T21:30:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-14T20:36:15.000Z (over 6 years ago)
- Last Synced: 2025-01-18T08:07:26.302Z (8 days ago)
- Language: TypeScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Example
```ts
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 {
@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
```