https://github.com/hifizz/type-tool
Safe type checker tool for JavaScript.
https://github.com/hifizz/type-tool
js-type type
Last synced: over 1 year ago
JSON representation
Safe type checker tool for JavaScript.
- Host: GitHub
- URL: https://github.com/hifizz/type-tool
- Owner: hifizz
- License: mit
- Created: 2019-01-20T05:02:39.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-20T07:55:17.000Z (over 7 years ago)
- Last Synced: 2025-01-22T12:29:19.173Z (over 1 year ago)
- Topics: js-type, type
- Language: TypeScript
- Homepage:
- Size: 112 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# type-tool
[](https://travis-ci.com/hifizz/type-tool)
[](https://codecov.io/gh/hifizz/type-tool)
[](https://github.com/prettier/prettier)
一个安全的变量类型检查工具。
## Install
Use yarn:
```bash
yarn add type-tool
```
Use npm:
```bash
npm i type-tool
```
## Usage
```js
import { isArray } from 'type-tool'
const targetVariable = []
const isVariableArray = isArray(targetVariable)
console.log(isVariableArray) // true
```
```js
import * as type from 'type-tool'
const targetVariable = []
const isVariableArray = type.isArray(targetVariable)
console.log(isVariableArray) // true
```
## Documentation
借助 `Object.prototype.toString` 来返回真实的变量类型。
```js
// 看下面的例子
console.log(typeof []) // "object"
console.log(Object.prototype.toString.call([])) // "[Object Array]"
console.log(typeof null) // "object"
console.log(Object.prototype.toString.call(null)) // "[Object Null]"
```
### API
**getTypeString**
`getTypeString(o: any): string` Alias `Object.prototype.toString.call` Return string like "[Object Null]" "[Object Array]".
**isString** `isString(o: any): boolean`
**isNumber** `isNumber(o: any): boolean`
**isBoolean** `isBoolean(o: any): boolean`
**isSymbol** `isSymbol(o: any): boolean`
**isArray** `isArray(o: any): boolean`
**isObject** `isObject(o: any): boolean`
**isFunction** `isFunction(o: any): boolean`
**isError** `isError(o: any): boolean`
**isNull** `isNull(o: any): boolean`
**isUndefined** `isUndefined(o: any): boolean`
**isDate** `isDate(o: any): boolean`
**isMath** `isMath(o: any): boolean`