🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

qn-code-msg

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qn-code-msg

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

latest
npmnpm
Version
0.0.5
Version published
Weekly downloads
10
900%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

error-code

FAQs

Package last updated on 22 Apr 2025

Did you know?

Socket

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.

Install

Related posts