npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sugar-type

v0.0.6

Published

Object type inspect

Readme

sugar-type

sugar2.0框架的对象类型检测类库

API

inspect(target)

  • target - 对象,任何类型的对象
  • 返回 - 该对象的类型,字符串表示,如"string","number","error","map"等

用例如下:

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。

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

isSymbol(target)

返回是否为对象类型,用法如下:

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

isObject(target)

返回是否为对象类型,用法如下:

type.isObject({}); // true
type.isObject(123); // false

isArray(target)

返回是否为数组类型,用法如下:

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

isFunction(target)

返回是否为函数类型,用法如下:

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

isRegExp(target)

返回是否为正则类型,用法如下:

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

isDate(target)

返回是否为日期类型,用法如下:

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

isMath(target)

返回是否为数学类型,用法如下:

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

isError(target)

返回是否为错误类型,用法如下:

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

isJSON(target)

返回是否为JSON类型,用法如下:

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

isArguments(target)

返回是否为参数类型,用在函数里的参数数组判断,用法如下:

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

isMap(target)

返回是否为map类型,用法如下:

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类型,用法如下:

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类型