Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/okunishinishi/node-iftype
Node.js module to check types.
https://github.com/okunishinishi/node-iftype
Last synced: 2 months ago
JSON representation
Node.js module to check types.
- Host: GitHub
- URL: https://github.com/okunishinishi/node-iftype
- Owner: okunishinishi
- License: mit
- Created: 2015-09-27T23:56:36.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T16:40:11.000Z (about 2 years ago)
- Last Synced: 2024-10-28T14:54:53.192Z (3 months ago)
- Language: JavaScript
- Size: 155 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
iftype
==========[![Build Status][bd_travis_shield_url]][bd_travis_url]
[![npm Version][bd_npm_shield_url]][bd_npm_url]
[![JS Standard][bd_standard_shield_url]][bd_standard_url][bd_repo_url]: https://github.com/okunishinishi/node-iftype
[bd_travis_url]: http://travis-ci.org/okunishinishi/node-iftype
[bd_travis_shield_url]: http://img.shields.io/travis/okunishinishi/node-iftype.svg?style=flat
[bd_travis_com_url]: http://travis-ci.com/okunishinishi/node-iftype
[bd_travis_com_shield_url]: https://api.travis-ci.com/okunishinishi/node-iftype.svg?token=
[bd_license_url]: https://github.com/okunishinishi/node-iftype/blob/master/LICENSE
[bd_codeclimate_url]: http://codeclimate.com/github/okunishinishi/node-iftype
[bd_codeclimate_shield_url]: http://img.shields.io/codeclimate/github/okunishinishi/node-iftype.svg?style=flat
[bd_codeclimate_coverage_shield_url]: http://img.shields.io/codeclimate/coverage/github/okunishinishi/node-iftype.svg?style=flat
[bd_gemnasium_url]: https://gemnasium.com/okunishinishi/node-iftype
[bd_gemnasium_shield_url]: https://gemnasium.com/okunishinishi/node-iftype.svg
[bd_npm_url]: http://www.npmjs.org/package/iftype
[bd_npm_shield_url]: http://img.shields.io/npm/v/iftype.svg?style=flat
[bd_standard_url]: http://standardjs.com/
[bd_standard_shield_url]: https://img.shields.io/badge/code%20style-standard-brightgreen.svgCheck types
Installation
-----```bash
$ npm install iftype --save
```Usage
---------```javascript
'use strict'const iftype = require('iftype')
function CustomType(){
}//----------------------------
// Check if type is 'string'
//----------------------------
iftype(123).is('string') // => false
iftype(function foo(){}).is('string') // => false
iftype(new CustomType()).is('string') // => false
iftype(["foo", "bar"]).is('string') // => false
iftype("bar").is('string') // => true
iftype(null).is('string') // => false
iftype(undefined).is('string') // => false//----------------------------
// Check if type is 'number'
//----------------------------
iftype(123).is('number') // => true
iftype(function foo(){}).is('number') // => false
iftype(new CustomType()).is('number') // => false
iftype(["foo", "bar"]).is('number') // => false
iftype("bar").is('number') // => false
iftype(null).is('number') // => false
iftype(undefined).is('number') // => false//----------------------------
// Check if type is 'object'
//----------------------------
iftype(123).is('object') // => false
iftype(function foo(){}).is('object') // => false
iftype(new CustomType()).is('object') // => true
iftype(["foo", "bar"]).is('object') // => true
iftype("bar").is('object') // => false
iftype(null).is('object') // => false
iftype(undefined).is('object') // => false//----------------------------
// Check if type is 'array'
//----------------------------
iftype(123).is('array') // => false
iftype(function foo(){}).is('array') // => false
iftype(new CustomType()).is('array') // => false
iftype(["foo", "bar"]).is('array') // => true
iftype("bar").is('array') // => false
iftype(null).is('array') // => false
iftype(undefined).is('array') // => false//----------------------------
// Check if type is 'function'
//----------------------------
iftype(123).is('function') // => false
iftype(function foo(){}).is('function') // => true
iftype(new CustomType()).is('function') // => false
iftype(["foo", "bar"]).is('function') // => false
iftype("bar").is('function') // => false
iftype(null).is('function') // => false
iftype(undefined).is('function') // => false//----------------------------
// Check if type is CustomType
//----------------------------
iftype(123).is(CustomType) // => false
iftype(function foo(){}).is(CustomType) // => false
iftype(new CustomType()).is(CustomType) // => true
iftype(["foo", "bar"]).is(CustomType) // => false
iftype("bar").is(CustomType) // => false
iftype(null).is(CustomType) // => false
iftype(undefined).is(CustomType) // => false```
API
----| Signature | Description |
| --- | --- |
| iftype(val).is(type) | Check if type match. |
| iftype(val).isString() | Check if string. |
| iftype(val).isNumber() | Check if number. |
| iftype(val).isObject() | Check if object. |
| iftype(val).isArray() | Check if array. |
| iftype.is(type, val) | Check if type match. |
| iftype.isString(val) | Check if string. |
| iftype.isNumber(val) | Check if number. |
| iftype.isObject(val) | Check if object. |
| iftype.isArray(val) | Check if array. |License
-------
This software is released under the [MIT License](https://github.com/okunishinishi/node-iftype/blob/master/LICENSE).Links
------