Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/martijndeh/check
A simple type checker for JavaScript inspired by Meteor's check.
https://github.com/martijndeh/check
Last synced: 9 days ago
JSON representation
A simple type checker for JavaScript inspired by Meteor's check.
- Host: GitHub
- URL: https://github.com/martijndeh/check
- Owner: martijndeh
- License: mit
- Created: 2016-02-14T22:16:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-22T20:21:42.000Z (about 7 years ago)
- Last Synced: 2024-07-26T20:57:59.924Z (4 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 19
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Check
[![Build Status](https://travis-ci.org/martijndeh/lego.svg?branch=master)](https://travis-ci.org/martijndeh/check)
[![Coverage Status](https://coveralls.io/repos/github/martijndeh/check/badge.svg?branch=master)](https://coveralls.io/github/martijndeh/check?branch=master)A type checker for JavaScript inspired by Meteor's check.
```
npm install type-check-system --save
```## Usage
Check if `value` is a string.
```js
let value = 'This is a string.';
check(value, String);
```Check if `value` is a list of strings.
```js
let value = ['a', 'b', 'c'];
check(value, [String]);
```Check if `value` is a string, or null.
```js
let value = 'string';
check(value, String, null);
```Check if `value` is an object with key `id` with type string.
```js
let value = {
id: '0af390f0-abb6-4ef6-b9af-6287e6aab172'
};
check(value, {id: String});
```Please have a look at the tests to see more examples.
## Limitations
This library does not expose any `Match`-like functions, like Meteor's check library. Instead, this library only uses a check based on patterns to keep it's api simple. If you want `Match` features, have a look at [meteor-check](https://www.npmjs.com/package/meteor-check) instead.
## Tests
To execute the tests, run the following commands:
```
npm run build
npm run test
```