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

chai-asserttype-extra

v2.0.15

Published

Chai plugin for type assertions with TypeScript support / Chai 類型斷言外掛程式,支援 TypeScript

Readme

chai-asserttype-extra

Chai 類型斷言外掛程式,支援 TypeScript,提供多種類型檢查方法。

Chai plugin for type assertions with TypeScript support, providing various type checking methods.

特色 (Features)

  • 支援多種類型檢查 / Supports various type checking (number, string, array, etc.)
  • 整合自定義數字檢查(integer, float, infinity, zero, positive, negative)/ Integrates custom number checks
  • 支援 TypeScript 類型推斷 / Supports TypeScript type inference
  • 提供鏈式呼叫方法 / Provides chainable methods
  • 多種安裝方式 / Multiple installation methods

安裝 (Installation)

npm install chai chai-asserttype-extra
# or
yarn add chai chai-asserttype-extra

使用方式 (Usage)

引入方式 (Import Options)

// CommonJS
const ChaiPluginAssertType = require('chai-asserttype-extra');

// ES Module
import ChaiPluginAssertType from 'chai-asserttype-extra';
import { ChaiPlugin as ChaiPluginAssertType } from 'chai-asserttype-extra';

安裝外掛程式 (Install Plugin)

// 方法一:使用 install() 自動處理 TypeScript 類型 / Method 1: Use install() for TypeScript type handling
const chai = ChaiPluginAssertType.install();

// 方法二:傳入現有的 Chai 實例 / Method 2: Pass existing Chai instance
const chai = ChaiPluginAssertType.install(require('chai'));

// 方法三:直接使用 use() / Method 3: Direct use with use()
const chai = require('chai');
chai.use(ChaiPluginAssertType);

支援的類型檢查 (Supported Type Checks)

列出所有方法 (List All Methods)

console.log(ChaiPluginAssertType.list());
// [ 'array', 'boolean', 'date', 'float', 'function', 'integer',
//   'nan', 'negative', 'null', 'number', 'object', 'positive',
//   'regexp', 'string', 'undefined', 'zero' ]

數字類型 (Number Types)

// 基本數字 / Basic number
expect(1).to.be.number();
expect(27.11).to.be.number;

// 整數 / Integer
expect(27).to.be.integer();
expect(27).to.be.integer;

// 浮點數 / Float
expect(27.11).to.be.float();
expect(27.11).to.be.float;

// 無限大 / Infinity
expect(Infinity).to.be.infinity();

// 零 / Zero
expect(0).to.be.zero();
expect(-0).to.be.zero();

// 正數 / Positive
expect(5).to.be.positive();

// 負數 / Negative
expect(-5).to.be.negative();

// NaN
expect(NaN).to.be.nan();

其他類型 (Other Types)

// 字串 / String
expect('').to.be.string();
expect('foobar').to.be.string();

// 布林值 / Boolean
expect(true).to.be.boolean();
expect(false).to.be.boolean();

// 物件 / Object
expect({}).to.be.object();

// 陣列 / Array
expect([]).to.be.array();
expect([1, 2, 3]).to.be.array();

// 日期 / Date
expect(new Date()).to.be.date();

// 函式 / Function
expect(() => true).to.be.function();

// 正規表示式 / RegExp
expect(/abc/).to.be.regexp();

// null
expect(null).to.be.null();

// undefined
expect(undefined).to.be.undefined();

API 參考 (API Reference)

ChaiPluginAssertType.list()

取得所有支援的類型檢查方法名稱陣列。

Returns array of all supported type checking method names.

ChaiPluginAssertType.install(chai?)

安裝外掛程式並回傳 Chai 實例。

Installs plugin and returns Chai instance.

| 參數 (Parameter) | 類型 (Type) | 說明 (Description) | |-----------------|------------|-------------------| | chai | ChaiObject | 可選的 Chai 實例 / Optional Chai instance |

參考連結 (Reference)

授權 (License)

ISC