# sugar-type

> Object type inspect

Latest version **0.0.6** (published 2018-04-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install sugar-type
pnpm add sugar-type
yarn add sugar-type
bun add sugar-type
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2018-04-04 |
| First published | 2017-04-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ss.feng |
| Maintainers | fengshangshi |

## Links

- npm: https://www.npmjs.com/package/sugar-type
- Repository: https://github.com/fengshangshi/sugar-type
- Homepage: https://github.com/fengshangshi/sugar-type#readme
- Issues: https://github.com/fengshangshi/sugar-type/issues
- npm.io page: https://npm.io/package/sugar-type

## Recent versions

- 0.0.6 (latest) — 2018-04-04
- 0.0.5 — 2018-03-29
- 0.0.4 — 2018-03-29
- 0.0.3 — 2017-04-26
- 0.0.2 — 2017-04-26
- 0.0.1 — 2017-04-24

## README

# sugar-type
sugar2.0框架的对象类型检测类库

## API
### inspect(target)
* target - 对象，任何类型的对象
* 返回 - 该对象的类型，字符串表示，如"string"，"number"，"error"，"map"等

用例如下:

```js
const type = require('sugar-type');

type.inspect([]); //'array'
type.inspect({test: 1}); //'object'
type.inspect('123'); //'string'
type.inspect(123); //'number'
type.inspect(NaN); //'number'
type.inspect(function(){}); //'function'
type.inspect(new Date()); //'date'
type.inspect(new Error()); //'error'
type.inspect(new Map()); //'map'

```

还有更加快捷的判断，返回布尔值，如下：

### isEmpty(target)
检查Array、Object、Map、Set4个对象是否为空，其他类型会返回true。

```js
type.isEmpty({}); // true
type.isEmpty({a: 1}); // false
type.isEmpty(123); // true
```

### isSymbol(target)
返回是否为对象类型，用法如下：

```js
type.isSymbol(Symbol('symbol')); // true
type.isSymbol(123); // false
```

### isObject(target)
返回是否为对象类型，用法如下：

```js
type.isObject({}); // true
type.isObject(123); // false
```
### isArray(target)
返回是否为数组类型，用法如下：

```js
type.isArray([1, 2, 3]); // true
type.isArray('string'); // false
```

### isFunction(target)
返回是否为函数类型，用法如下：

```js
type.isFunction(function(){}); // true
type.isFunction('string'); // false
```

### isRegExp(target)
返回是否为正则类型，用法如下：

```js
type.isRegExp(/^abc/g); // true
type.isRegExp(true); // false
```

### isDate(target)
返回是否为日期类型，用法如下：

```js
type.isDate(new Date()); // true
type.isDate(true); // false
```

### isMath(target)
返回是否为数学类型，用法如下：

```js
type.isMath(Math); // true
type.isMath(123); // false
```

### isError(target)
返回是否为错误类型，用法如下：

```js
type.isError(new Error('这里有问题')); // true
type.isError(true); // false
```


### isJSON(target)
返回是否为JSON类型，用法如下：

```js
type.isJSON(JSON); // true
type.isJSON(true); // false
```



### isArguments(target)
返回是否为参数类型，用在函数里的参数数组判断，用法如下：

```js
function fn(param) {
	console.log(type.isArguments(arguments)); // true
	console.log(type.isArguments(true)); // false
}
fn('param');
```



### isMap(target)
返回是否为map类型，用法如下：

```js
let map = new Map();
map.set(1, '我是小1');
map.set(2, '我是小二');
map.set(3, '我是小三');
type.isMap(map); // true
type.isMap(true); // false
```


### isSet(target)
返回是否为set类型，用法如下：

```js
let set = new Set();
set.add(1);
set.add(2);
set.add(3);
type.isMap(set); // true
type.isMap(true); // false
```



### isString(target)
返回是否为字符串类型





### isNumber(target)
返回是否为数字类型




### isBoolean(target)
返回是否为布尔类型




### isNull(target)
返回是否为null类型




### isUndefined(target)
返回是否为undefined类型

---
_Source: https://npm.io/package/sugar-type · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
