https://github.com/zemse/deno-type-check
Runtime type check library for Deno
https://github.com/zemse/deno-type-check
Last synced: 10 months ago
JSON representation
Runtime type check library for Deno
- Host: GitHub
- URL: https://github.com/zemse/deno-type-check
- Owner: zemse
- Created: 2020-05-21T21:39:28.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-24T12:17:03.000Z (about 6 years ago)
- Last Synced: 2025-02-09T02:32:10.761Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# type_check
Runtime type check library for Deno
```typescript
import { t, validate, check } from 'https://deno.land/x/type_check/mod.ts';
function submitAge(age: number): void {
// Throws if not a unsigned integer (non-negative)
validate(age, t.uint);
// OR To receive a boolean
if (check(age, t.uint)) {
}
}
function fetchTransactionAmount(hash: string): number {
// Throws if not a 32 byte hex string
validate(hash, t.hex32);
// OR To receive a boolean
if (check(hash, t.hex32)) {
}
}
// To work with optional multiple types
function enterAmount(input: number | string) {
// Throws if all the type checks fail
validateMultiple(input, [t.number, t.hex]);
}
```
## Type Checkers Available
### String
- string
- hex
- hex20
- hex32
- hex65
### Nubmer
- number
- int
- uint
- uint8
### Objects
- array
- uint8array
- functionObject
- object