https://github.com/tur-nr/node-isval
Yet another value type validator.
https://github.com/tur-nr/node-isval
Last synced: 3 months ago
JSON representation
Yet another value type validator.
- Host: GitHub
- URL: https://github.com/tur-nr/node-isval
- Owner: tur-nr
- License: mit
- Created: 2014-10-06T21:40:51.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-28T06:49:07.000Z (over 9 years ago)
- Last Synced: 2025-02-01T00:07:06.985Z (4 months ago)
- Language: JavaScript
- Size: 177 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# isval
isval is a helper module that validates any given value. It overcomes common JavaScript issues with type checking, like `NaN` and `null` values.
[](https://travis-ci.org/tur-nr/node-isval)
### Example
```js
var isval = require('isval');
var string = 'I am a string';assert.ok(isval(string, 'string'));
```## Installation
### Node
To install isval in a Node application use npm.
```
$ npm install isval
```### Browser
No tests available for the browser but you may try using it via [webpack](https://github.com/webpack/webpack).
```
$ webpack index.js isval.js
```## Test
To run tests use npm.
```
$ npm install
$ npm test
```## Documentation
### Basic Usage
The following types are available:
* `'string'`
* `'number'`
* `'boolean'`
* `'function'`
* `'object'`
* `'array'`
* `'regex'`
* `'regexp'`
* `'date'`
* `'null'`
* `'undefined'`
* `'NaN'`
* `'arguments'`
* `'integer'`
* `'generator'`, `(function *(){})()`
* `'generator*'`, `function *() {}`Types can also be literal values:
* `String`
* `Number`
* `Boolean`
* `Object`
* `null`
* `undefined`
* `NaN`### Instance Of
Passing a constructor function will check if the value is an `instanceof` of that "Class".
```js
var buffer = new ArrayBuffer();
isval(buffer, ArrayBuffer);
```### Truthy Values
Passing no type will check for truthy values.
```js
isval(1);
isval('true');
```## API
#### isval(*<value>*, *[type]*)
## License
[MIT](LICENSE)
Copyright (c) 2014 [Christopher Turner](https://github.com/tur-nr)