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
- Host: GitHub
- URL: https://github.com/darky/dtypecheck
- Owner: darky
- License: mit
- Created: 2017-07-08T13:15:56.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-09T17:17:27.000Z (over 8 years ago)
- Last Synced: 2025-02-23T20:47:19.269Z (over 1 year ago)
- Topics: dynamic, typecheck
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
})();
```