# @arcjet/redact 中文文档

规范地址：https://npmcn.com/package/%40arcjet/redact/

版本：1\.15\.0
npm 元数据更新时间：2026-10-28T18:47:25.253Z
中文译文更新时间：2026-11-06T14:45:59.531Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40arcjet/redact
原文对照：https://npmcn.com/package/%40arcjet/redact/?lang=original
项目主页：https://arcjet.com/
源码仓库：https://github.com/arcjet/arcjet-js

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：27.4 kB，5 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=22\.21\.0 \<23 \|\| \>=24\.5\.0
- 运行依赖：1 个
- 首次发布：2024-09-02T19:25:32.497Z
- 最新版本发布：2026-10-28T18:47:24.805Z
- 近 30 天下载量：39485（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：56（近 12 个月 30 个）

## 中文简介

Arcjet 敏感信息编辑库

## 安装

```sh
npm install @arcjet/redact
```

也可以使用：`pnpm add @arcjet/redact`、`yarn add @arcjet/redact`、`bun add @arcjet/redact`

## README

[![Arcjet Logo](https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg)](https://arcjet.com/)

# `@arcjet/redact`

[![npm badge](https://img.shields.io/npm/v/%40arcjet%2Fredact?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0)](https://www.npmjs.com/package/@arcjet/redact)

[弧喷](https://arcjet.com/) 帮助开发人员在几行中保护自己的应用 代码。 执行费率限制、机器人保护、电子邮件核查和防御 打击普通攻击.

这是 [弧喷](https://arcjet.com/) 类型脚本和 JavaScript 敏感信息 编辑库.

-   [npm 软件包 (`@arcjet/redact`(中文(简体) )](https://www.npmjs.com/package/@arcjet/redact)
-   [GitHub 源代码 (`redact/` 内 `arcjet/arcjet-js`(中文(简体) )](https://github.com/arcjet/arcjet-js/tree/main/redact)

见 [`docs.arcjet.com`](https://docs.arcjet.com/redact/reference) 更多关于API.

## 这是什么?

此软件包为编辑敏感信息提供了功能. 工作是在WebAssembly完成的,但从JavaScript这里调用.

Web Assembly 文件在 [`@arcjet/redact-wasm`](https://github.com/arcjet/arcjet-js/tree/main/redact-wasm)。 。 。 . 更多关于我们为什么维护 WebAssembly 和 JavaScript 项目的信息 这个, 见 [“这是什么?” `@arcjet/analyze-wasm`](https://github.com/arcjet/arcjet-js/tree/main/analyze-wasm#what-is-this)。 。 。 .

## 我什么时候用这个?

您可以使用此软件包来编辑本地的敏感信息 . 您可以编辑电子邮件地址、信用卡号码等. 也可以扭转这个过程:不编辑所发现的东西.

## 安装

这套方案只是无害环境管理. 在 Node.js 用 npm 安装 :

```sh
npm install @arcjet/redact
```

## 使用

```ts
import { redact } from "@arcjet/redact";

const value = "Hi, my name is John and my email adress is john@example.com";

const [redacted, unredact] = await redact(value, {
  entities: ["email", "phone-number"],
});
console.log(redacted);
// => "Hi, my name is John and my email adress is <Redacted email #0>"

const unredacted = unredact("Your email address is <Redacted email #0>");
console.log(unredacted); // "Your email address is john@example.com"
```

## API 密码

此软件包导出标识符 [`redact`](https://npmcn.com/package/%40arcjet/redact/#readme-redactcandidate-options)。 。 。 . 没有默认导出 .

此套件导出 [类型脚本](https://www.typescriptlang.org/) 类型 [`ArcjetSensitiveInfoType`](https://npmcn.com/package/%40arcjet/redact/#readme-arcjetsensitiveinfotype) 财务报告和审定财务报表 [`RedactOptions`](https://npmcn.com/package/%40arcjet/redact/#readme-redactoptions)。 。 。 .

### `ArcjetSensitiveInfoType`

此类型代表了可以检测的敏感信息类型 从盒子里出来.

###### 类型

```ts
type ArcjetSensitiveInfoType =
  | "credit-card-number"
  | "email"
  | "ip-address"
  | "phone-number";
```

### `RedactOptions`

您可以通过这些选项来配置 `redact` 工作时.

###### 字段

-   `contextWindowSize` (单位:千美元)`number`,默认值 : `1`(中文(简体) ) 需要考虑上下文的符号数量
-   `detect` (单位:千美元)`(tokens: string[]) => ReadonlyArray<string | undefined>`,可选) - 识别敏感信息的自定义检测功能
-   `entities` (单位:千美元)`Array<string>`,默认:所有内建和检测实体) ——哪些实体要修改;这包括内置 [`ArcjetSensitiveInfoType`](https://npmcn.com/package/%40arcjet/redact/#readme-arcjetsensitiveinfotype)s 和 您返回的自定义类型 `detect` 函数
-   `replace` (单位:千美元)`(entity: string, plaintext: string) => string | undefined`,可选) ——自定义替换功能来控制敏感信息是如何存在的 已编辑

### `redact(candidate[, options])`

编辑字符串中的敏感信息。 您可以使用返回的密码 `unredact` 函数以在稍后恢复原始值.

###### 参数

-   `candidate` (单位:千美元)`string`(中文(简体) ) ——要编辑的字符串
-   `options` (单位:千美元)[`RedactOptions`](https://npmcn.com/package/%40arcjet/redact/#readme-redactoptions),可选) - 编辑内容和方式的配置

###### 回返

此函数返回 a `Promise` {\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}这决定了与修饰者纠缠在一起 字符串和可以卸取的函数( y)`Promise<[string, Unredact]>`) (中文(简体) ).

## 许可证

[Apache 许可证,2.0版本](http://www.apache.org/licenses/LICENSE-2.0) © [Arcjet实验室股份有限公司.](https://arcjet.com/)

## 常见问题

### @arcjet/redact 是什么？

Arcjet 敏感信息编辑库

### 如何安装 @arcjet/redact？

在项目目录运行 npm install @arcjet/redact，或使用 pnpm add / yarn add / bun add。

### @arcjet/redact 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @arcjet/redact 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @arcjet/redact 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=22\.21\.0 \<23 \|\| \>=24\.5\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @arcjet/redact 可以商用吗？

@arcjet/redact 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @arcjet/redact 的下载量有多少？

根据 npm 官方下载统计，@arcjet/redact 在 2026/10/07 – 2026/11/05 这 30 天内被下载 39,485 次，日均约 1,316 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @arcjet/redact 还在维护吗？

最新版本 1\.15\.0 发布于 2026/10/29（8 天前）；至今共发布 56 个版本，其中过去 12 个月发布了 30 个；首次发布于 2024/09/03。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

