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 🙏

© 2024 – Pkg Stats / Ryan Hefner

type-cmj

v1.0.1

Published

Determine the variable type.

Downloads

2

Readme

一个判断变量类型的 js 库。

ES6 模块, 浏览器使用

安装

npm i type-cmj -S

使用

const type = require('type-cmj')

type.isArray([]); // true
type.isObject([]); // false

// or

const { isArray, isString } = require('type-cmj')

isArray([]); // true
isString([]); // false

方法

is*

| 方法 | 描述 | 参数类型 | 返回值 | | --- | --- | --- | --- | | isArray(value) | 判断value是否为数组(Array) | Any | Boolean(true/false) | | isBigInt(value) | 判断value是否为BigInt | Any | Boolean(true/false) | | isBoolean(value) | 判断value是否为布尔值(Boolean) | Any | Boolean(true/false) | | isFunction(value) | 判断value是否为函数(Function) | Any | Boolean(true/false) | | isNull(value) | 判断value是否为null | Any | Boolean(true/false) | | isNumber(value) | 判断value是否为数字(Number) | Any | Boolean(true/false) | | isObject(value) | 判断value是否为对象(Object) | Any | Boolean(true/false) | | isString(value) | 判断value是否为字符串(String) | Any | Boolean(true/false) | | isSymbol(value) | 判断value是否为Symbol | Any | Boolean(true/false) | | isUndefined(value) | 判断value是否为undefined | Any | Boolean(true/false) | | isAsyncFunction(value) | 判断value是否为同步函数(Async Function) | Any | Boolean(true/false) | | isDecimal(value) | 判断value是否为小数 | Any | Boolean(true/false) | | isInfinity(value) | 判断value是否为Infinity | Any | Boolean(true/false) | | isNan(value) | 判断value是否为NaN | Any | Boolean(true/false) | | isNumeric(value) | 判断value是否为数字或字符串数字 | Any | Boolean(true/false) | | isDate(value) | 判断value是否为日期(Date) | Any | Boolean(true/false) | | isDom(value) | 判断value是否为Dom对象 | Any | Boolean(true/false) | | isDOMException(value) | 判断value是否为Dom异常对象(DOMException) | Any | Boolean(true/false) | | isError(value) | 判断value是否为Error对象 | Any | Boolean(true/false) | | isjQueryObj(value) | 判断value是否为jQuery对象 | Any | Boolean(true/false) | | isMap(value) | 判断value是否为Map | Any | Boolean(true/false) | | isPromise(value) | 判断value是否为Promise | Any | Boolean(true/false) | | isRegExp(value) | 判断value是否为正则表达式(RegExp) | Any | Boolean(true/false) | | isSet(value) | 判断value是否为Set | Any | Boolean(true/false) | | isWeakMap(value) | 判断value是否为WeakMap | Any | Boolean(true/false) | | isWeakSet(value) | 判断value是否为WeakSet | Any | Boolean(true/false) | | isPrototype(value) | 判断value是否为Prototype | Any | Boolean(true/false) | | isURL(value) | 判断value是否为URL对象,注意是对象不是字符串! | Any | Boolean(true/false) |

whichType(value)

判断参数(value)的类型

  • 接受的参数(value)类型: Any
  • 返回值类型: Object
    • typeof: 值为typeof value
    • prototype: 值为Object.prototype.toString.call(value)的后位类型

例:

const { whichType } = require('type-cmj')

whichType('');

/* 返回值
{
  typeof: "string",
  prototype: "String"
}
*/

whichType(Promise.resolve());

/* 返回值
{
  typeof: "object",
  prototype: "Promise"
}
*/