An open API service indexing awesome lists of open source software.

https://github.com/darky/dtypecheck

Dynamic typecheck helper
https://github.com/darky/dtypecheck

dynamic typecheck

Last synced: 11 months ago
JSON representation

Dynamic typecheck helper

Awesome Lists containing this project

README

          

# dtypecheck - dynamic typecheck helper

#### Note: It works with `env NODE_ENV=development`

Examples:

### Simple

```javascript
const t = require("dtypecheck");
const {expect} = require("chai");

const fn = t(
number => `${number}`,
number => expect(number).a(`number`),
string => expect(string).a(`string`)
);

fn(1) // Good
fn([1, 2]) // Bad
```
### Async

```javascript
const t = require("dtypecheck");
const {expect} = require("chai");

const fn = t(
async (number) => `${number}`,
async (number) => expect(number).a(`number`),
async (string) => expect(string).a(`string`)
);

(async () {
await fn(1) // Good
await fn([1, 2]) // Bad
})();
```