
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
qn-code-msg
Advanced tools
一个用于管理错误码和错误消息映射的轻量级工具库。支持添加、获取、检查、修改和删除错误码及其对应的消息。
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);
暂无
| 函数名 | 描述 | 参数 | 返回值 |
|---|---|---|---|
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
FAQs
We found that qn-code-msg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.