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

@shencom/utils-judge

v1.3.0

Published

判断数据格式等工具

Downloads

112

Readme

@shencom/utils-judge

判断数据格式等工具

Install

pnpm add @shencom/utils

# or

pnpm add @shencom/utils-judge

Basic Usage

import { IsNumber, IsObject } from '@shencom/utils';
// import { IsObject, IsNumber } from '@shencom/utils-judge';

Methods

IsDataType

  • 说明: 判断数据类型
  • 类型: (data: any, type?: string) => AllDataType|boolean
  • 参数:
    • data: 数据
    • type: 类型
  • 示例:
    IsDataType('xxx'); // 'string'
    IsDataType('xxx', 'string'); // true
    IsDataType(123); // 'number'
    IsDataType(false); // 'boolean'
    IsDataType([]); // 'array'
    IsDataType({}); // 'object'
    IsDataType(null); // 'null'
    IsDataType((f) => f); // 'function'
    IsDataType(undefined); // 'undefined'

IsObject

  • 说明: 判断是否是对象
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsObject({}); // true
    IsObject(''); // false

IsNull

  • 说明: 判断是否是 Null
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsNull(null); // true

IsFunction

  • 说明: 判断是否是函数
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsFunction((f) => f); // true
    IsFunction(''); // false

IsBoolean

  • 说明: 判断是否是布尔类型
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsBoolean(false); // true

IsNumber

  • 说明: 判断是否是 number 类型
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsNumber(123); // true
    IsNumber('123'); // false

IsString

  • 说明: 判断是否是字符串
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsString(123); // false
    IsString('123'); // true

IsArray

  • 说明: 判断是否是数组
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsArray([123]); // true
    IsArray('123'); // false

IsDate

  • 说明: 判断是否是日期类型
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsDate(new Date()); // true
    IsDate('123'); // false

IsRegexp

  • 说明: 判断是否是正则表达式
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsRegexp(/\s/); // true
    IsRegexp('123'); // false

IsUndefined

  • 说明: 判断是否是 undefined
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsUndefined(undefined); // true
    IsUndefined('123'); // false

IsWindow

  • 说明: 判断是否是 window
  • 类型: (val?: any) => boolean
  • 参数:
    • val: 数据
  • 示例:
    IsWindow(window); // true
    IsWindow(Global); // false

IsDataEmpty

  • 说明: 判断数据是否为空
  • 类型: (data?: any) => boolean
  • 参数:
    • data: 数据
  • 示例:
    IsDataEmpty([0, 1, 2, 3], [0]); // true
    IsDataEmpty(''); // false