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

qn-code-msg

v0.0.5

Published

一个用于管理错误码和错误消息映射的轻量级工具库。支持添加、获取、检查、修改和删除错误码及其对应的消息。

Readme

qn-code-message

一个用于管理错误码和错误消息映射的轻量级工具库。支持添加、获取、检查、修改和删除错误码及其对应的消息。

安装

npm install qn-code-message

基本用法

// ESM 导入
import { addCode, getCode, removeCode, hasCode } from "qn-code-message";

// 添加错误码
addCode(1001, "服务器错误");

// 获取错误码消息
console.log(getCode(1001)); // 输出: 服务器错误

// 检查错误码是否存在
if (hasCode(1001)) {
	console.log("错误码1001存在");
}

// 修改错误码
setCode(1001, "服务器内部错误");

// 删除错误码
removeCode(1001);

// 将错误码转为对象
const errorsObject = errorCodeObject();
console.log(errorsObject);

API 文档

暂无

模块函数

| 函数名 | 描述 | 参数 | 返回值 | | ------------------------- | ------------------------------------ | --------------------------------- | ---------------------------------------- | | addCode(code, msg = '') | 添加错误码及其消息 | code: 错误码msg: 错误消息 | 无 | | getCode(code) | 获取错误码对应的消息 | code: 错误码 | 错误消息字符串,若不存在则返回 undefined | | hasCode(code) | 检查错误码是否存在 | code: 错误码 | 布尔值 | | setCode(code, msg = '') | 设置错误码对应的消息,若不存在则添加 | code: 错误码msg: 错误消息 | 无 | | removeCode(code) | 删除错误码 | code: 错误码 | 无 | | getAllCode() | 获取所有错误码及消息 | 无 | Map 对象 | | errorCodeObject() | 将错误码 Map 转换为普通对象 | 无 | Object |

预设错误码

该库包含一系列预设的错误码,导入后即可使用,具体可查看源代码中的常量定义。

测试

运行单元测试:

npm test