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

@buka/error-codes

v1.1.1

Published

The error codes management tool library maintained by Buka Inc.

Downloads

220

Readme

@buka/error-codes

结构化错误码管理库,提供 64 位结构化错误码的编码、解码和管理能力。

安装

pnpm add @buka/error-codes
npm install @buka/error-codes
yarn add @buka/error-codes

使用指南

创建错误码

import { ErrorCode, ErrorCategory } from "@buka/error-codes";

const errorCode = new ErrorCode({
  category: ErrorCategory.BUSINESS, // 错误类别
  systemId: 1, // 系统 ID
  moduleId: 100, // 模块 ID
  sequenceId: 42, // 序列号
});

使用 Base32 字符串构造

systemIdmoduleIdsequenceIdversion 除了接受数值外,还支持传入 Crockford Base32 字符串,库会自动解码为对应数值。这在从可读格式各段构造错误码时非常方便:

// 可读格式: B0-AAAC-AAAB-AAA
// 直接使用各段 Base32 字符串
const errorCode = new ErrorCode({
  category: ErrorCategory.BUSINESS,
  systemId: "AAAC", // 等价于 systemId: 2
  moduleId: "AAAB", // 等价于 moduleId: 1
  sequenceId: "AAA", // 等价于 sequenceId: 0
});

// 也可以混合使用 number 和 string
const mixed = new ErrorCode({
  category: ErrorCategory.BUSINESS,
  systemId: "AAAC",
  moduleId: 1,
  sequenceId: 0,
});

转换格式

// 转换为可读格式字符串
const readable = errorCode.toString(); // B0-AAAC-AAAB-AAA

// 转换为 64 位整数
const bigint = errorCode.toBigInt();

// 从可读格式解析
const parsed = ErrorCode.fromString("B0-AAAC-AAAB-AAA");

错误类别

ErrorCategory 枚举提供以下错误类别:

  • ErrorCategory.AUTH (10) - 认证与安全
  • ErrorCategory.BUSINESS (11) - 业务逻辑异常
  • ErrorCategory.CONFLICT (12) - 数据冲突
  • ErrorCategory.DEGRADE (13) - 功能降级/熔断
  • ErrorCategory.FEATURE (15) - 功能不可用
  • ErrorCategory.RATE_LIMIT (24) - 流量限制
  • ErrorCategory.SYSTEM (25) - 系统故障
  • ErrorCategory.THIRD_PARTY (26) - 第三方服务异常
  • ErrorCategory.VALIDATION (27) - 参数校验错误

详细说明见规范文档。

详见 docs/specification.md 了解完整的错误码规范设计、位段划分、编码规则、错误类别定义和保留错误码说明。