Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahdinosaur/typeof-is
utility functions to check primitive types using typeof
https://github.com/ahdinosaur/typeof-is
Last synced: 17 days ago
JSON representation
utility functions to check primitive types using typeof
- Host: GitHub
- URL: https://github.com/ahdinosaur/typeof-is
- Owner: ahdinosaur
- Created: 2017-03-24T05:41:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-04-10T14:58:00.000Z (over 7 years ago)
- Last Synced: 2024-10-20T04:40:01.826Z (25 days ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# typeof-is
utility functions to check primitive types using [`typeof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)
```shell
npm install --save typeof-is
```## background
i prefer using functions over `typeof ===` expressions`, so i often find myself writing these functions inline in my modules.
i wrote this module because the related modules i found seemed to implement the kitchen sink of types, when i usually only need these and i'd rather install a specific module for other types.
## example
```js
const is = require('typeof-is')is.boolean('true') // false
is.boolean(true) // true
is.function(() => {}) // true
is.number(true) // false
is.number(NaN) // true
is.object({}) // true
is.object(null) // true
is.object(undefined) // false
is.string('') // true
is.string(1) // false
is.symbol(Symbol('a')) // true
is.undefined(null) // false
```## usage
### `is = require('typeof-is')`
### `is.boolean(value)`
### `is.function(value)`
### `is.number(value)`
### `is.object(value)`
### `is.string(value)`
### `is.symbol(value)`
### `is.undefined(value)`## license
The Apache License
Copyright © 2017 Michael Williams
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.