Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danigb/hi-typeof
Generate isStr, isNum and other typeof functions
https://github.com/danigb/hi-typeof
Last synced: 13 days ago
JSON representation
Generate isStr, isNum and other typeof functions
- Host: GitHub
- URL: https://github.com/danigb/hi-typeof
- Owner: danigb
- License: mit
- Created: 2016-06-16T14:24:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-06-16T17:40:17.000Z (over 8 years ago)
- Last Synced: 2024-10-07T22:09:05.467Z (about 1 month ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hi-typeof [![npm](https://img.shields.io/npm/v/hi-typeof.svg?style=flat-square)](https://www.npmjs.com/package/hi-typeof)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) [![license](https://img.shields.io/npm/l/hi-typeof.svg?style=flat-square)](https://www.npmjs.com/package/hi-typeof)
Some sugar to the javascript `typeof` operator. Generate isStr, isNum and other typeof functions.
## Usage
```js
var is = require('hi-typeof')var isStr = is('string')
isStr('a string here') // => truevar isNum = is('number')
isNum(16) // => true
isNum('16') // => falsevar isFn = is('function')
isFn(isFn) // => true// Create inverse test
var isDef = is('undefined', false)
isDef(isDef) // => true
isDef(isDef.currentTime) // => false
```Basically, it's a function I use a lot and just makes the code clear and concise. It does not add any extra functionallity to the `typeof` operator.
## Source
This is the smallest module I've published (sorry for the npm package pollution), so here is the full source code:
```js
module.exports = function (t, r) {
var b = r === false
return function (o) { return (typeof o === t) !== b }
}
```## License
MIT License