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

@taicode/common-base

v3.1.0

Published

基础工具库,提供常用的工具函数和类。

Downloads

625

Readme

@taicode/common-base

基础工具库,提供常用的工具函数和类。

📦 安装

npm install @taicode/common-base

🚀 使用方式

完整导入

// 导入所有工具
import { catchIt, logger, debounce, throttle, Disposer } from '@taicode/common-base'

按需导入

// 只导入需要的工具
import { catchIt } from '@taicode/common-base/catch'
import { logger } from '@taicode/common-base/logger'
import { debounce } from '@taicode/common-base/debounce'
import { throttle } from '@taicode/common-base/throttle'
import { Disposer } from '@taicode/common-base/disposer'

🔧 快速开始

错误捕获示例

import { catchIt } from '@taicode/common-base/catch'

// 捕获 Promise 错误
const [result, error] = await catchIt(fetch('/api/data'))
if (error) {
  console.error('请求失败:', error)
} else {
  console.log('数据:', result)
}

其他工具

更多工具和详细用法请查看各模块的类型定义或源码。

🛡️ 导出控制

为确保 API 稳定性,包使用 exports 字段控制模块导出:

使用方式

允许

// 完整导入
import { catchIt, logger } from '@taicode/common-base'

// 按需导入
import { catchIt } from '@taicode/common-base/catch'

禁止

// 直接访问内部文件
import { catchIt } from '@taicode/common-base/catch/catch'  // ❌

配置

使用通配符模式自动映射所有子模块:

{
  "exports": {
    ".": "./output/index.js",
    "./*": "./output/*/index.js"
  }
}

优势:新增模块自动支持按需导入,无需手动配置。

🏗️ 开发

构建命令

npm run build    # 构建项目
npm run dev      # 开发模式(监听文件变化)
npm test         # 运行测试

添加新模块

  1. source/ 下创建新模块目录
  2. 创建模块的 index.ts 文件导出公共接口
  3. source/index.ts 中添加模块导出
  4. 编写单元测试

💡 新模块会自动支持按需导入,无需手动配置 exports。

📄 许可证

ISC

🤝 贡献

欢迎提交 Issue 和 Pull Request!

在提交代码前,请确保:

  1. 代码通过所有测试
  2. 添加了相应的单元测试
  3. 更新了相关文档
  4. 遵循现有的代码风格