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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@nuwatop/utils

v0.1.1

Published

一个提供常用类型判断和空值判断的 TypeScript 工具类库

Readme

@nuwatop/utils

一个提供常用类型判断和空值判断的 TypeScript 工具类库。

安装

npm install @nuwatop/utils
# 或
pnpm add @nuwatop/utils
# 或
yarn add @nuwatop/utils

使用方法

import { IsUtils } from '@nuwatop/utils';

// 判断字符串
IsUtils.isString('hello'); // true
IsUtils.isEmptyString(''); // true
IsUtils.isEmptyString('   '); // true

// 判断数字
IsUtils.isNumber(123); // true
IsUtils.isNumber(NaN); // false
IsUtils.isNumber(Infinity); // false

// 判断日期
IsUtils.isDate(new Date()); // true
IsUtils.isValidDate('2024-01-01'); // true
IsUtils.isValidDate('invalid'); // false

// 判断金额
IsUtils.isAmount(100.50); // true
IsUtils.isAmount(-10); // false
IsUtils.isAmountString('1,000.50'); // true
IsUtils.isAmountString('1000.50'); // true

// 判断数组
IsUtils.isArray([1, 2, 3]); // true
IsUtils.isEmptyArray([]); // true
IsUtils.isEmptyArray([1, 2]); // false

// 判断空值
IsUtils.isEmpty(null); // true
IsUtils.isEmpty(undefined); // true
IsUtils.isEmpty(''); // true
IsUtils.isEmpty([]); // true
IsUtils.isEmpty({}); // true

// 判断未定义
IsUtils.isUndefined(undefined); // true
IsUtils.isNull(null); // true
IsUtils.isNullOrUndefined(null); // true
IsUtils.isNullOrUndefined(undefined); // true

// 判断是否有值
IsUtils.hasValue('hello'); // true
IsUtils.hasValue(null); // false
IsUtils.hasValue(undefined); // false
IsUtils.hasValue(''); // false

API 文档

字符串判断

  • isString(value: unknown): value is string - 判断是否为字符串
  • isEmptyString(value: unknown): boolean - 判断字符串是否为空(包括空字符串、null、undefined)

数字判断

  • isNumber(value: unknown): value is number - 判断是否为有效数字(排除 NaN 和 Infinity)

日期判断

  • isDate(value: unknown): value is Date - 判断是否为 Date 对象
  • isValidDate(value: unknown): boolean - 判断是否为有效的日期字符串或日期对象

金额判断

  • isAmount(value: unknown): boolean - 判断是否为金额(正数,可包含小数)
  • isAmountString(value: unknown): boolean - 判断是否为金额字符串(支持千分位分隔符)

数组判断

  • isArray<T>(value: unknown): value is T[] - 判断是否为数组
  • isEmptyArray(value: unknown): boolean - 判断数组是否为空

空值判断

  • isEmpty(value: unknown): boolean - 判断值是否为空(null、undefined、空字符串、空数组、空对象)
  • hasValue<T>(value: T | null | undefined): value is T - 判断值是否有值(不为空、不为未定义)

未定义判断

  • isUndefined(value: unknown): value is undefined - 判断是否为 undefined
  • isNull(value: unknown): value is null - 判断是否为 null
  • isNullOrUndefined(value: unknown): value is null | undefined - 判断是否为 null 或 undefined

License

MIT