# @frontmcp/utils 中文文档

规范地址：https://npmcn.com/package/%40frontmcp/utils/

版本：1\.12\.2
npm 元数据更新时间：2026-11-14T21:10:35.491Z
中文译文更新时间：2026-11-15T15:08:50.586Z
软件包许可：Apache-2\.0

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

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

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

- 包体积（解压后）：1.1 MB，255 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=24\.0\.0
- 运行依赖：3 个
- peer 依赖：ioredis ^5\.0\.0，@vercel/kv ^2\.0\.0 \|\| ^3\.0\.0，@upstash/redis ^1\.34\.0，@frontmcp/lazy-zod 1\.12\.2
- 首次发布：2026-01-04T03:23:30.917Z
- 最新版本发布：2026-11-14T21:10:35.130Z
- 近 30 天下载量：15041（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：111（近 12 个月 111 个）

## 中文简介

FrontMCP的共享助手:URI模板,命名,跨平台加密和PKCE,密钥值存储,文件系统和环境检测

## 安装

```sh
npm install @frontmcp/utils
```

也可以使用：`pnpm add @frontmcp/utils`、`yarn add @frontmcp/utils`、`bun add @frontmcp/utils`

## README

# @ frontmcp/ 使用

FrontMCP包的共享助手:名称和URI模板,跨平台加密,密钥值存储,文件系统访问,环境检测等. 这是一个内部包: `@frontmcp/sdk` 以及其它问题 `@frontmcp/*` 软件包依赖它并安装它。 只当您自己的代码像插件一样需要这些帮助时直接导入它.

[![npm](https://img.shields.io/npm/v/@frontmcp/utils.svg)](https://www.npmjs.com/package/@frontmcp/utils) [![License](https://img.shields.io/npm/l/@frontmcp/utils.svg)](https://github.com/agentfront/frontmcp/blob/main/LICENSE)

## 安装

```bash
npm install @frontmcp/utils
```

它需要节点.js 24或后. 密码、 async 上下文、 事件发送器、 环境和路径帮助器也建有浏览器, 通过软件包选择 `imports` 地图. `@frontmcp/lazy-zod` 是需要的同伴依赖(它需要) `zod` 4. 其他可选,每个存储后端一个:

| 可选对等点 | 启用 |
| --- | --- |
| `ioredis` | `createStorage({ type: 'redis' })` 财务报告和审定财务报表 `RedisStorageAdapter` |
| `@vercel/kv` | `createStorage({ type: 'vercel-kv' })` |
| `@upstash/redis` | `createStorage({ type: 'upstash' })` |

## 使用量

```ts
import { createStorage, expandUriTemplate, matchUriTemplate, sha256Hex, toCase } from '@frontmcp/utils';

matchUriTemplate('tickets://{id}/comments/{commentId}', 'tickets://T-1/comments/42');
// { id: 'T-1', commentId: '42' }

expandUriTemplate('tickets://{id}', { id: 'T-2' }); // 'tickets://T-2'
toCase(['create', 'ticket'], 'snake'); // 'create_ticket'
sha256Hex('hello world'); // 'b94d27b9...'

const storage = await createStorage({ type: 'memory' });
await storage.set('ticket:T-1', 'open', { ttlSeconds: 60 });
await storage.get('ticket:T-1'); // 'open'
```

## 里面有什么东西

| 区域 | 出口 |
| --- | --- |
| 命名 | `splitWords`, (中文(简体) ), `toCase`, (中文(简体) ), `shortHash`, (中文(简体) ), `ensureMaxLen`, (中文(简体) ), `idFromString` |
| URIs 参考文献 | `isValidMcpUri`, (中文(简体) ), `extractUriScheme`, (中文(简体) ), `parseUriTemplate`, (中文(简体) ), `matchUriTemplate`, (中文(简体) ), `expandUriTemplate`, (中文(简体) ), `extractTemplateParams` (RFC 3986 URIs,RFC 6570模板) |
| 路径 | `trimSlashes`, (中文(简体) ), `joinPath`,和跨平台 `pathJoin`, (中文(简体) ), `pathResolve`, (中文(简体) ), `basename`, (中文(简体) ), `dirname`, (中文(简体) ), `extname` |
| 内容 | `sanitizeToJson`, (中文(简体) ), `inferMimeType`, (中文(简体) ), `safeStringify`, (中文(简体) ), `canonicalJson` |
| HTTP 密码 | `validateBaseUrl`, (中文(简体) ), `buildSetCookie`, (中文(简体) ), `parseCookies`, (中文(简体) ), `getCookie`, (中文(简体) ), `isLocalhost`, (中文(简体) ), `isSecureRequest` |
| 网络 | `classifyIpAddress`, (中文(简体) ), `isGloballyRoutableIp`, (中文(简体) ), `parseIpv4`, (中文(简体) ), `expandIpv6`, (中文(简体) ), `isRedirectResponse`,用于SSRF(服务器侧请求伪造)检查 |
| 输出的 HTTP | `validateOutboundUrl`, (中文(简体) ), `sendOutboundRequest`, (中文(简体) ), `outboundFailureCategory`,用于请求客户端选择的 URL |
| 逃跑 | `escapeHtml`, (中文(简体) ), `escapeHtmlAttr`, (中文(简体) ), `escapeJsString`, (中文(简体) ), `safeJsonForScript` |
| 密码 | `sha256`, (中文(简体) ), `sha256Hex`, (中文(简体) ), `hmacSha256`, (中文(简体) ), `hkdfSha256`, (中文(简体) ), `encryptAesGcm`, (中文(简体) ), `decryptAesGcm`, (中文(简体) ), `randomBytes`, (中文(简体) ), `randomUUID`, (中文(简体) ), `timingSafeEqual`, (中文(简体) ), `base64urlEncode`, (中文(简体) ), `base64urlDecode` |
| 捷克 | `generateCodeVerifier`, (中文(简体) ), `generateCodeChallenge`, (中文(简体) ), `verifyCodeChallenge`, (中文(简体) ), `generatePkcePair` (RFC 7636) (中文(简体) ) |
| 网络呼号 | `signWebhookMessage`, (中文(简体) ), `webhookSignatureHeaders`, (中文(简体) ), `verifyWebhookSignature`, (中文(简体) ), `isStandardWebhookSecret`, (中文(简体) ), `generateWebhookMessageId` (标准网呼) |
| 加密, 键 | `encryptValue`, (中文(简体) ), `decryptValue`, (中文(简体) ), `signData`, (中文(简体) ), `verifyData`, (中文(简体) ), `KeyPersistence`, (中文(简体) ), `createKeyPersistence` |
| 存储 | `createStorage`, (中文(简体) ), `createMemoryStorage`, (中文(简体) ), `TypedStorage`, (中文(简体) ), `EncryptedTypedStorage`,以及用于内存、Redis、Vercel KV、Upstash和文件系统的适配器 |
| 文件系统 | `readFile`, (中文(简体) ), `writeFile`, (中文(简体) ), `mkdir`, (中文(简体) ), `stat`, (中文(简体) ), `fileExists`, (中文(简体) ), `readJSON`, (中文(简体) ), `writeJSON`, (中文(简体) ), `ensureDir`, (中文(简体) ), `isDirEmpty`, (中文(简体) ), `runCmd` 还有更多 仅限节点.js; `fs` 首次使用的负载. |
| 进程 | `spawnOwned`, (中文(简体) ), `reapOrphans`, (中文(简体) ), `watchParent`, (中文(简体) ), `watchPath`, (中文(简体) ), `stopProcessTree`, (中文(简体) ), `signalProcessTree`仅限节点; `child_process` 首次使用的负载. |
| 环境 | `getEnv`, (中文(简体) ), `isProduction`, (中文(简体) ), `isDevelopment`, (中文(简体) ), `isEdgeRuntime`, (中文(简体) ), `isServerless`, (中文(简体) ), `getRuntimeContext`, (中文(简体) ), `isNode`, (中文(简体) ), `isBrowser` |
| 背景、事件 | `AsyncLocalStorage`, (中文(简体) ), `EventEmitter`浏览器 |
| 安全正则 | `isPatternSafe`, (中文(简体) ), `createSafeRegExp`, (中文(简体) ), `safeTest`, (中文(简体) ), `safeMatch`, (中文(简体) ), `safeReplace`,反对ReDoS(定期拒绝服务) |
| 模型工具调用 | `processPlatformToolCalls`,通过OpenAI,克洛德或Vercel AI工具呼叫您 `callTool` 函数并返回该平台格式的结果 |
| 机器标识 | `getMachineId`, (中文(简体) ), `setMachineIdOverride`, (中文(简体) ), `getHostname` |

## 相关软件包

-   [`@frontmcp/sdk`](https://www.npmjs.com/package/@frontmcp/sdk):基于这些帮助者的架构.
-   [`@frontmcp/auth`](https://www.npmjs.com/package/@frontmcp/auth):使用密码,PKCE和存储辅助.
-   [`@frontmcp/storage-sqlite`](https://www.npmjs.com/package/@frontmcp/storage-sqlite): 一个执行此软件包的 SQLite 存储适配器 `StorageAdapter`。 。 。 .

## 捐款

资料来源: [`libs/utils`](https://github.com/agentfront/frontmcp/tree/main/libs/utils)欢迎提出问题和拉动请求;见 [捐款额](https://github.com/agentfront/frontmcp/blob/main/CONTRIBUTING.md)。 。 。 .

## 许可证

阿帕奇2.0 (英语). 见 [自由主义](https://github.com/agentfront/frontmcp/blob/main/LICENSE)。 。 。 .

## 常见问题

### @frontmcp/utils 是什么？

FrontMCP的共享助手:URI模板,命名,跨平台加密和PKCE,密钥值存储,文件系统和环境检测

### 如何安装 @frontmcp/utils？

在项目目录运行 npm install @frontmcp/utils，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@frontmcp/lazy-zod（1\.12\.2）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @frontmcp/utils 支持 TypeScript 吗？

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

### @frontmcp/utils 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @frontmcp/utils 需要什么版本的 Node\.js？

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

### @frontmcp/utils 可以商用吗？

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

### @frontmcp/utils 的下载量有多少？

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

### @frontmcp/utils 还在维护吗？

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

