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

payload-is

v0.4.0

Published

A comprehensive TypeScript/JavaScript type checking library providing functions to check data types, collections, primitives, and built-in objects

Downloads

251

Readme

Status GitHub Issues GitHub Pull Requests License


📝 目录

🧐 简介

Payload-is 提供了一套简洁、直观的 JS/TS 数据类型校验方法,无任何第三方依赖,适用于多种场景。

🏁 快速开始

安装

npm install payload-is

用法示例

import {
  isArray,
  isEmptyArray,
  isFullArray,
  isBigInt,
  isBigIntObject,
  isBigIntArray,
  isBoolean,
  isTrue,
  isFalse,
  isBooleanObject,
  isArrayBuffer,
  isSharedArrayBuffer,
  isArrayBufferLike,
  isArrayBufferView,
  isDataView,
  isInt8Array,
  isUint8Array,
  isUint8ClampedArray,
  isInt16Array,
  isUint16Array,
  isInt32Array,
  isUint32Array,
  isFloat32Array,
  isFloat64Array,
  isBigInt64Array,
  isBigUint64Array,
  isTypedArray,
  isSet,
  isMap,
  isWeakSet,
  isWeakMap,
  isWeakRef,
  isMapEntries,
  isDate,
  isValidDate,
  isInvalidDate,
  isBlob,
  isFile,
  isFormData,
  isHeaders,
  isRequest,
  isResponse,
  isError,
  isAggregateError,
  isEvalError,
  isNativeError,
  isRangeError,
  isReferenceError,
  isSyntaxError,
  isTypeError,
  isURIError,
  isFunction,
  isAsyncFunction,
  isAsyncGeneratorFunction,
  isGeneratorFunction,
  isAsyncGenerator,
  isGenerator,
  isAsyncIterable,
  isIterable,
  isAsyncIterator,
  isIterator,
  isNil,
  isNull,
  isUndefined,
  isNumber,
  isValidNumber,
  isInvalidNumber,
  isNumberObject,
  isNumberArray,
  isObject,
  isPlainObject,
  isEmptyObject,
  isFullObject,
  isPrimitive,
  isPromise,
  isPromiseLike,
  isRegExp,
  isString,
  isEmptyString,
  isFullString,
  isStringObject,
  isStringArray,
  isSymbol,
  isSymbolObject,
  getType,
  getTag,
  getDataType,
  isWeakKey,
  isPropertyKey,
  enumerableKeys,
  hasFromJSON,
  hasToJSON,
} from "payload-is";

常用示例

数组

isArray([]); // true
isEmptyArray([]); // true
isFullArray([1]); // true

BigInt

isBigInt(1n); // true
isBigIntObject(Object(1n)); // true
isBigIntArray([1n, 2n]); // true

布尔值

isBoolean(true); // true
isBooleanObject(new Boolean(true)); // true
isTrue(true); // true
isFalse(false); // true

Buffer & TypedArray

isArrayBuffer(new ArrayBuffer(32)); // true
isSharedArrayBuffer(new SharedArrayBuffer(32)); // true
isArrayBufferLike(new ArrayBuffer(32)); // true
isArrayBufferLike(new SharedArrayBuffer(32)); // true
isArrayBufferView(new Uint8Array(8)); // true
isDataView(new DataView(new ArrayBuffer(32))); // true
isInt8Array(new Int8Array(32)); // true
isUint8Array(new Uint8Array(32)); // true
isUint8ClampedArray(new Uint8ClampedArray(32)); // true
isInt16Array(new Int16Array(32)); // true
isUint16Array(new Uint16Array(32)); // true
isInt32Array(new Int32Array(32)); // true
isUint32Array(new Uint32Array(32)); // true
isFloat32Array(new Float32Array(32)); // true
isFloat64Array(new Float64Array(32)); // true
isBigInt64Array(new BigInt64Array(32)); // true
isBigUint64Array(new BigUint64Array(32)); // true
isTypedArray(new Int8Array(32)); // true

集合

isSet(new Set()); // true
isMap(new Map()); // true
isWeakSet(new WeakSet()); // true
isWeakMap(new WeakMap()); // true
isWeakRef(new WeakRef({})); // true
isMapEntries([
  [1, 2],
  [3, 4],
]); // true

日期

isDate(new Date()); // true
isValidDate(new Date(2022, 2, 22)); // true
isInvalidDate(new Date("invalid")); // true

DOM

isBlob(new Blob()); // true
isFile(new File([], "a.txt")); // true
isFormData(new FormData()); // true
isHeaders(new Headers()); // true
isRequest(new Request("https://example.com")); // true
isResponse(new Response()); // true

错误对象

isError(new Error()); // true
isAggregateError(new AggregateError([])); // true
isEvalError(new EvalError()); // true
isRangeError(new RangeError()); // true
isReferenceError(new ReferenceError()); // true
isSyntaxError(new SyntaxError()); // true
isTypeError(new TypeError()); // true
isURIError(new URIError()); // true
isNativeError(new TypeError()); // true

函数

isFunction(function () {}); // true
isAsyncFunction(async function () {}); // true
isGeneratorFunction(function* () {}); // true
isAsyncGeneratorFunction(async function* () {}); // true

Generator

isGenerator((function* () {})()); // true
isAsyncGenerator((async function* () {})()); // true

可迭代对象 & 迭代器

isIterable([]); // true
isAsyncIterable((async function* () {})()); // true
isIterator([].values()); // true
isAsyncIterator((async function* () {})()); // true

Nil

isNil(null); // true
isNil(undefined); // true
isNull(null); // true
isUndefined(undefined); // true

数字

isNumber(10); // true
isValidNumber(10); // true
isInvalidNumber(NaN); // true
isNumberObject(new Number(10)); // true
isNumberArray([1, 2, 3]); // true

对象

isObject({}); // true
isPlainObject({}); // true
isEmptyObject({}); // true
isFullObject({ a: 1 }); // true

原始类型

isPrimitive(1); // true
isPrimitive(null); // true
isPrimitive(undefined); // true

Promise

isPromise(Promise.resolve()); // true
isPromiseLike({ then() {} }); // true

正则表达式

isRegExp(/abc/); // true

字符串

isString(""); // true
isEmptyString(""); // true
isFullString("abc"); // true
isStringObject(new String("abc")); // true
isStringArray(["a", "b"]); // true

Symbol

isSymbol(Symbol()); // true
isSymbolObject(Object(Symbol())); // true

键 & 属性

isWeakKey({}); // true
isPropertyKey("a"); // true
enumerableKeys({ a: 1, b: 2 }); // ['a','b']

JSON 辅助

hasToJSON({
  toJSON() {
    return 1;
  },
}); // true
hasFromJSON(
  class {
    static fromJSON() {
      return new this();
    }
  },
); // true

🔧 测试

npm run test

✍️ 作者