# @decaf-ts/utils 中文文档

规范地址：https://npmcn.com/package/%40decaf-ts/utils/

版本：2\.0\.6
npm 元数据更新时间：2026-11-06T18:08:35.880Z
中文译文更新时间：2026-11-12T03:35:36.745Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：2.1 MB，338 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=20\.0\.0
- 运行依赖：33 个
- 首次发布：2025-04-21T22:33:28.706Z
- 最新版本发布：2026-11-06T18:08:34.944Z
- 近 30 天下载量：3044（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：128（近 12 个月 72 个）

## 中文简介

无咖啡因咖啡因的模块管理功用

## 安装

```sh
npm install @decaf-ts/utils
```

也可以使用：`pnpm add @decaf-ts/utils`、`yarn add @decaf-ts/utils`、`bun add @decaf-ts/utils`

## README

![Banner](https://npmcn.com/package/%40decaf-ts/utils/workdocs/assets/decaf-logo.svg)

## 无咖啡因的Utils模块

一个全面的TypeScript工具库,为命令行接口,输入处理,输出管理,文件系统操作,HTTP请求,文本处理等提供了强大的工具. 这个模块是建立强大的CLI应用程序的基础,具有标准化的输入解析,灵活的输出格式,以及丰富的一套公用功能.

![Licence](https://img.shields.io/github/license/decaf-ts/utils.svg?style=plastic) ![GitHub language count](https://img.shields.io/github/languages/count/decaf-ts/utils?style=plastic) ![GitHub top language](https://img.shields.io/github/languages/top/decaf-ts/utils?style=plastic)

[![Build & Test](https://github.com/decaf-ts/utils/actions/workflows/nodejs-build-prod.yaml/badge.svg)](https://github.com/decaf-ts/utils/actions/workflows/nodejs-build-prod.yaml) [![CodeQL](https://github.com/decaf-ts/utils/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/decaf-ts/utils/actions/workflows/codeql-analysis.yml)[![Snyk Analysis](https://github.com/decaf-ts/utils/actions/workflows/snyk-analysis.yaml/badge.svg)](https://github.com/decaf-ts/utils/actions/workflows/snyk-analysis.yaml) [![Pages builder](https://github.com/decaf-ts/utils/actions/workflows/pages.yaml/badge.svg)](https://github.com/decaf-ts/utils/actions/workflows/pages.yaml) [![.github/workflows/release-on-tag.yaml](https://github.com/decaf-ts/utils/actions/workflows/release-on-tag.yaml/badge.svg?event=release)](https://github.com/decaf-ts/utils/actions/workflows/release-on-tag.yaml)

![Open Issues](https://img.shields.io/github/issues/decaf-ts/utils.svg) ![Closed Issues](https://img.shields.io/github/issues-closed/decaf-ts/utils.svg) ![Pull Requests](https://img.shields.io/github/issues-pr-closed/decaf-ts/utils.svg) ![Maintained](https://img.shields.io/badge/Maintained%3F-yes-green.svg)

![Forks](https://img.shields.io/github/forks/decaf-ts/utils.svg) ![Stars](https://img.shields.io/github/stars/decaf-ts/utils.svg) ![Watchers](https://img.shields.io/github/watchers/decaf-ts/utils.svg)

![Node Version](https://img.shields.io/badge/dynamic/json.svg?url=https%3A%2F%2Fraw.githubusercontent.com%2Fbadges%2Fshields%2Fmaster%2Fpackage.json&label=Node&query=$.engines.node&colorB=blue) ![NPM Version](https://img.shields.io/badge/dynamic/json.svg?url=https%3A%2F%2Fraw.githubusercontent.com%2Fbadges%2Fshields%2Fmaster%2Fpackage.json&label=NPM&query=$.engines.npm&colorB=purple)

现有文件 [这里](https://decaf-ts.github.io/utils/)

最小尺寸: 34.4 KB kb gziped

### 说明

无咖啡因Utils模块是一个全面的TypeScript通用库,旨在将API标准化到整个寄存器,并为构建指令行界面(CLI)应用程序提供坚实的基础. 图书馆由几个关键组成部分组成:

#### CLI 模块

CLI模块为创建命令行应用程序提供了一个结构化的框架:

-   摘要 `Command` 用于执行自定义的 CLI 指令的分类,并附有标准化的输入处理、记录和执行流程
-   命令选项处理,支持普通旗帜,如动词,版本,帮助等.
-   标准化命令执行流程,并妥善处理错误

#### 输入模块

输入模块提供了处理用户输入和命令行参数的工具:

-   `UserInput` 类,用于创建包含各种输入类型(文本、数字、确认等)的交互式提示
-   支持输入验证、格式化和默认值
-   命令行参数分析类型检查和验证
-   在收到有效答复之前反复征求投入的方法

#### Utils 模块

Utils模块包含广泛的公用功能:

-   **文件系统操作**: 阅读、撰写、复制和删除文件和目录
-   **软件包管理**: 获取软件包信息,管理依赖性,以及版本处理
-   **HTTP 公用事业**: 从 URL 下载文件的简单客户端
-   **文本处理**:字符串插值、大小写转换(骆驼案、蛇案等)和正则表达式工具
-   **环境处理**: 处理环境变量和配置

#### 作家模块

Writers模块提供了处理命令输出的不同策略:

-   `OutputWriter` 界面定义输出处理的标准合同
-   `StandardOutputWriter` 用于处理有正确记录的标准命令行输出
-   `RegexpOutputWriter` 用于处理带有正则表达式和模式匹配的输出

#### 输出模块

产出单元为产出的格式和显示提供各种设施:

-   共同产出格式化功能
-   屏蔽显示能力

#### 测试助手

测试辅助工具在 `@decaf-ts/for-testing`; 此套件不再导出 `@decaf-ts/utils/tests`。 。 。 .

这个库作为无咖啡因CLI工具的轻版,为建设强大的命令行应用程序提供所有必要的基本公用事业,并有一致的输入处理,输出格式化和出错管理.

### 如何使用

-   [初始设置](https://npmcn.com/package/%40decaf-ts/utils/tutorials/For%20Developers.md#_initial-setup_)
-   [安装](https://npmcn.com/package/%40decaf-ts/utils/tutorials/For%20Developers.md#installation)

## 实例

### CLI 模块

#### 创建自定义命令

指令类为创建自定义的CLI指令提供基础,并有标准化的输入处理和执行流程.

```typescript
import { Command, CommandOptions } from '@decaf-ts/utils';

// Define input options interface
interface MyCommandOptions {
  filename: string;
  dryRun: boolean;
}

// Create a custom command class
class MyCommand extends Command<MyCommandOptions, string> {
  constructor() {
    // Define command options with their configurations
    const options: CommandOptions<MyCommandOptions> = {
      filename: {
        type: 'string',
        short: 'f',
        default: 'output.txt'
      },
      dryRun: {
        type: 'boolean',
        short: 'd',
        default: false
      }
    };

    super('my-command', options);
  }

  // Override the help method to provide custom help information
  protected help(): void {
    this.log.info(`
      Usage: my-command [options]

      Options:
        -f, --filename  Specify output filename (default: output.txt)
        -d, --dryRun    Run without making changes (default: false)
        -h, --help      Show help information
        -v, --version   Show version information
    `);
  }

  // Implement the run method to define command behavior
  protected async run(answers: { filename: string; dryRun: boolean }): Promise<string> {
    this.log.info(`Running command with filename: ${answers.filename}, dryRun: ${answers.dryRun}`);

    // Command implementation here

    return 'Command executed successfully';
  }
}

// Execute the command
async function main() {
  const command = new MyCommand();
  const result = await command.execute();
  console.log(result);
}

main().catch(console.error);
```

#### 与全权证书委员会管理机密

这个 `CredentialsCommand` 提供一种安全、跨平台的管理符的方法 以及发布脚本、CI管道和当地发展所使用的其他秘密. 它取代了将信使存储在平版文件的旧做法(`.npmtoken`, (中文(简体) ), `.token`, (中文(简体) ), `.confluence-token`)与OS键链存储同时保存 向后兼容 .

**决议令** (按此顺序排列) `get` 编号 : `resolveSecret()`:

1.  **环境变量** ——最高优先级;这是CI的用法
2.  **OS 键链** – macOS keychain, Linux libsecret, Linux Python 密钥环, Windows 证书管理器
3.  **遗留的纯文本文件** ——有警告的被贬后退

**内设机密:**

| 名称 | 新闻 var | 键链服务 | 账户 | 遗留文件 |
| --- | --- | --- | --- | --- |
| `npm` | `NPM_TOKEN` | `decaf-ts:npm` | 发布 | `.npmtoken` |
| `github` | `GH_TOKEN` | `decaf-ts:github` | gi | `.token` |
| `confluence` | `ATLASSIAN_API_TOKEN` | `decaf-ts:confluence` | api 密码 | `.confluence-token` |

自定义秘密名称也被支持 – env var 默认为 `<NAME>_TOKEN`,服务 `decaf-ts:<name>`,以及遗留文件 `.<name>-token`。 。 。 .

##### CLI 使用量( 单独)

```sh
# Resolve the npm publish token (prints to stdout, no trailing newline)
credentials --action get --name npm

# Resolve the github token using a non-default env var name
credentials --action get --name github --envVar GH_PAT

# Store a secret in the OS keychain
credentials --action store --name github --value ghp_xxxxxxxxxxxx

# Store a custom secret with fully overridden metadata
credentials --action store --name my-api \
  --envVar MY_API_TOKEN \
  --service "my-app:api" \
  --account "ci" \
  --value "sk_live_xxx"

# Interactive one-time setup (prompts for all built-in secrets, configures git helper)
credentials --action setup

# Setup and auto-delete legacy plaintext token files (.npmtoken, .token, .confluence-token)
credentials --action setup --rm

# Configure only the git credential helper (no secret enrollment)
credentials --action git-helper

# Use in a shell pipeline (e.g., set npm auth for publish)
npm config set //registry.npmjs.org/:_authToken "$(credentials --action get --name npm)"
```

##### CLI(通过无咖啡因CLI)的使用

```sh
# All subcommands are also available under the decaf CLI
decaf utils credentials get --name npm
decaf utils credentials store --name github --value ghp_xxxxxxxxxxxx
decaf utils credentials setup
decaf utils credentials setup --rm   # auto-deletes legacy token files
decaf utils credentials git-helper

# View help for any subcommand
decaf utils credentials --help
decaf utils credentials get --help
```

##### CI 使用( GitHub 动作 / GitLab CI)

CI中不需要键链访问——简单地将环境变量设定为 保密和 `resolveSecret()` 立即捡起它:

```yaml
# .github/workflows/release.yml
- name: Publish to npm
  env:
    NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
  run: |
    npm config set //registry.npmjs.org/:_authToken "$NPM_TOKEN"
    npm publish
```

发行脚本( E) :`tag-release`, (中文(简体) ), `npm publish`, (中文(简体) ), `git push`(电话) `resolveSecret("npm")` 财务报告和审定财务报表 `resolveSecret("github")` 内部,所以他们 在 CI 和键链中自动偏好 env vars .

##### 程序使用( TypeScript)

```typescript
import { resolveSecret, hasSecret } from '@decaf-ts/utils';

// Resolves using the same order: env var -> keychain -> legacy file
// Throws if no source provides a value.
const token = resolveSecret('npm');

// Non-throwing check
if (hasSecret('github')) {
  const ghToken = resolveSecret('github');
}

// Custom secret with overrides
const apiKey = resolveSecret('my-api', {
  envVar: 'MY_API_TOKEN',
  service: 'my-app:api',
  account: 'ci',
  legacyFile: '.my-api-token',
});
```

##### 本地设置走过

```sh
# 1. Run interactive setup with --rm (enrolls npm, github, confluence in the keychain
#    and auto-deletes legacy plaintext files)
credentials --action setup --rm

# 2. Verify resolution works
credentials --action get --name npm    # should print the token
credentials --action get --name github # should print the token

# 3. Future release scripts will now use the keychain automatically
```

#### 建造和出版总库

这个 `BundleCommand` 替换遗留根 `bin/bundle.js` 脚本: 读取 `bundles.json` 财务报告和审定财务报表 `package-template.json` (单份复制命令资产已运出) 内 `@decaf-ts/utils`),生成一个 `@decaf-ts/dist-*` 包件总数 `bundles.json` 条目 `--target` (默认) `<base-path>/bin/releases`, (中文(简体) ), 从工作空间解析每个捆绑的依赖的版本, 合并 npm 覆盖, 然后运行 `npm install` 财务报告和审定财务报表 `npm publish --access public` 每个 生成捆绑文件夹(等待) `--timeout` 出版之间的秒). 通过证书解析器(env var - > OS 键链 - > 遗留文件),并且从未被登录. `--dry-run` (或 `DRY_RUN=1`生成 仅显出.

```sh
# Preview the generated manifests without installing or publishing
bundle --dry-run

# Full run from the workspace root, custom target and publish pacing
bundle --target ./releases --timeout 30

# Via the decaf CLI wrapper
decaf utils bundle --dry-run
decaf utils bundle --base-path . --target ./releases --timeout 30
```

#### 显示文档文件夹

这个 `BuildDocsCommand` 替换遗留 `bin/build-docs.sh` 脚本:它 删除并重新创建文件文件夹( 默认) `<base-path>/docs`)和副本 读取( 默认) `<base-path>/README.md`成为它 `docs/README.md`。 。 。 .

```sh
build-docs
build-docs --base-path ./integrations

# Via the decaf CLI wrapper
decaf utils build-docs
decaf utils build-docs --base-path ./integrations
```

### 输入模块

#### 创建交互式提示

用户输入类允许您为收集用户输入创建交互式提示.

```typescript
import { UserInput } from '@decaf-ts/utils';

async function collectUserInfo() {
  // Create a text input for name
  const nameInput = new UserInput('name')
    .setMessage('What is your name?')
    .setInitial('User');

  // Create a number input for age with validation
  const ageInput = new UserInput('age')
    .setType('number')
    .setMessage('How old are you?')
    .setMin(0)
    .setMax(120)
    .setValidate(value => {
      if (value < 18) return 'You must be at least 18 years old';
      return true;
    });

  // Create a confirmation input
  const confirmInput = new UserInput('confirm')
    .setType('confirm')
    .setMessage('Is this information correct?')
    .setInitial(true);

  // Ask for all inputs and get the answers
  const answers = await UserInput.ask([nameInput, ageInput, confirmInput]);

  console.log(`Hello ${answers.name}, you are ${answers.age} years old.`);
  console.log(`Information confirmed: ${answers.confirm ? 'Yes' : 'No'}`);

  return answers;
}

collectUserInfo().catch(console.error);
```

#### 使用方便输入方法

用户输入为常见输入情景提供了静态方便方法.

```typescript
import { UserInput } from '@decaf-ts/utils';

async function quickInputExample() {
  // Ask for text input
  const name = await UserInput.askText('name', 'What is your name?', undefined, 'User');

  // Ask for number input
  const age = await UserInput.askNumber('age', 'How old are you?', 0, 120);

  // Ask for confirmation
  const confirm = await UserInput.askConfirmation('confirm', 'Is this information correct?', true);

  // Ask for text with validation and retry until valid
  const email = await UserInput.insistForText(
    'email',
    'What is your email address?',
    (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value),
    undefined,
    undefined,
    false,
    3 // Maximum 3 attempts
  );

  console.log(`Name: ${name}, Age: ${age}, Email: ${email}, Confirmed: ${confirm}`);
}

quickInputExample().catch(console.error);
```

#### 解析命令行参数

```typescript
import { UserInput, ParseArgsOptionsConfig } from '@decaf-ts/utils';

// Define command-line options
const options: ParseArgsOptionsConfig = {
  verbose: {
    type: 'boolean',
    short: 'V',
    default: false
  },
  output: {
    type: 'string',
    short: 'o',
    default: 'output.txt'
  },
  count: {
    type: 'string',
    short: 'c',
    default: '10'
  }
};

// Parse command-line arguments
const args = UserInput.parseArgs(options);

console.log('Parsed arguments:', args.values);
console.log('Positional arguments:', args.positionals);
```

### Utils 模块

#### 文件系统操作

```typescript
import { 
  readFile, 
  writeFile, 
  patchFile, 
  getAllFiles, 
  copyFile, 
  renameFile, 
  deletePath 
} from '@decaf-ts/utils';

// Read a file
const content = readFile('./config.json');
console.log('File content:', content);

// Write to a file
writeFile('./output.txt', 'Hello, world!');

// Patch a file with replacements
patchFile('./template.txt', {
  '{{name}}': 'John Doe',
  '{{date}}': new Date().toISOString()
});

// Get all files in a directory
const files = getAllFiles('./src', (file) => file.endsWith('.ts'));
console.log('TypeScript files:', files);

// Copy a file
copyFile('./source.txt', './destination.txt');

// Rename a file
renameFile('./old-name.txt', './new-name.txt');

// Delete a file or directory
deletePath('./temp');
```

#### 软件包管理

```typescript
import { 
  getPackage, 
  getPackageVersion, 
  setPackageAttribute, 
  getDependencies, 
  installDependencies 
} from '@decaf-ts/utils';

// Get package information
const pkg = getPackage();
console.log('Package:', pkg);

// Get package version
const version = getPackageVersion();
console.log('Version:', version);

// Set a package attribute
setPackageAttribute('version', '1.0.1');

// Get dependencies
async function manageDependencies() {
  const deps = await getDependencies();
  console.log('Production dependencies:', deps.prod);
  console.log('Development dependencies:', deps.dev);
  console.log('Peer dependencies:', deps.peer);

  // Install dependencies
  await installDependencies({
    prod: ['lodash', 'axios'],
    dev: ['typescript', 'jest']
  });
}

manageDependencies().catch(console.error);
```

#### HTTP 公用事业

```typescript
import { HttpClient } from '@decaf-ts/utils';

async function downloadExample() {
  try {
    // Download a file from a URL
    const content = await HttpClient.downloadFile('https://example.com/api/data.json');
    console.log('Downloaded content:', content);

    // Parse JSON content
    const data = JSON.parse(content);
    console.log('Parsed data:', data);

    return data;
  } catch (error) {
    console.error('Download failed:', error);
    throw error;
  }
}

downloadExample().catch(console.error);
```

#### 文本处理

```typescript
import { 
  padEnd, 
  patchPlaceholders, 
  patchString, 
  toCamelCase, 
  toSnakeCase, 
  toKebabCase, 
  toPascalCase, 
  toENVFormat 
} from '@decaf-ts/utils';

// Pad a string
const padded = padEnd('Hello', 10, '-');
console.log(padded); // 'Hello-----'

// Replace placeholders
const template = 'Hello, ${name}! Today is ${day}.';
const filled = patchPlaceholders(template, {
  name: 'Alice',
  day: 'Monday'
});
console.log(filled); // 'Hello, Alice! Today is Monday.'

// Replace strings
const patched = patchString('Hello, world!', {
  'world': 'universe'
});
console.log(patched); // 'Hello, universe!'

// Case conversion
const text = 'hello world';
console.log(toCamelCase(text));   // 'helloWorld'
console.log(toSnakeCase(text));   // 'hello_world'
console.log(toKebabCase(text));   // 'hello-world'
console.log(toPascalCase(text));  // 'HelloWorld'
console.log(toENVFormat(text));   // 'HELLO_WORLD'
```

### 测试助手

测试辅助工具在 [`@decaf-ts/for-testing`](https://github.com/decaf-ts/for-testing); 此软件包不再提供 `@decaf-ts/utils/tests` 子路径.

### 作家模块

#### 使用标准输出Writer

```typescript
import { StandardOutputWriter } from '@decaf-ts/utils';

// Create a promise executor
const executor = {
  resolve: (value: string) => console.log(`Command succeeded with: ${value}`),
  reject: (error: Error) => console.error(`Command failed with: ${error.message}`)
};

// Create a standard output writer
const writer = new StandardOutputWriter('ls -la', executor);

// Handle command output
writer.data('File list output...');
writer.data('file1.txt');
writer.data('file2.txt');

// Handle command completion
writer.exit(0, ['Command executed successfully']);
```

#### 使用 RegexpOutputWriter

```typescript
import { RegexpOutputWriter } from '@decaf-ts/utils';

// Create a promise executor
const executor = {
  resolve: (value: string) => console.log(`Found version: ${value}`),
  reject: (error: Error) => console.error(`Error: ${error.message}`)
};

// Create a regexp output writer that matches version numbers
const writer = new RegexpOutputWriter('node --version', executor, /v(\d+\.\d+\.\d+)/);

// Process output that contains a version number
writer.data('v14.17.0');  // This will automatically resolve with "v14.17.0"

// Process error output
writer.error('Command not found: node');  // This will be logged as an error
```

## 编码原则

-   在文件夹中分组类似的功能( 与命名空间对应, 但没有任何命名空间声明)
-   每个文件一个类别;
-   每个文件一个接口(除非接口只是用作类型);
-   组合类型作为每个文件夹的.ts文件类型中的其他接口;
-   每个文件夹中的常数或常数组;
-   每个文件夹中的装饰器组;
-   总是从特定文件导入, 绝不从文件夹或索引文件导入( 其他软件包的依赖性除外 );
-   在适用的情况下,更倾向于使用既定的设计样板:
    -   Singleton(可以是反派. \* 谨慎使用;
    -   工厂;
    -   观察员;
    -   战略;
    -   建造者;
    -   诸如此类;

### 相关

[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=decaf-ts&repo=decaf-ts)](https://github.com/decaf-ts/decaf-ts)

### 社会

[![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/decaf-ts/)

#### 语文

![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white) ![JavaScript](https://img.shields.io/badge/JavaScript-F7DF1E?style=for-the-badge&logo=javascript&logoColor=black) ![NodeJS](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge&logo=node.js&logoColor=white) ![ShellScript](https://img.shields.io/badge/Shell_Script-121011?style=for-the-badge&logo=gnu-bash&logoColor=white)

## 获得帮助

如果您有错误报告, 请回答问题或建议 [创建一个新问题](https://github.com/decaf-ts/ts-workspace/issues/new/choose)。 。 。 .

## 捐款

我感谢对这一项目作出的任何贡献。 请阅读 [这个](https://npmcn.com/package/%40decaf-ts/utils/workdocs/98-Contributing.md) 要开始.

## 支助

第一种最简单的方法就是支持它 [捐款](https://npmcn.com/package/%40decaf-ts/utils/workdocs/98-Contributing.md). 甚至在文档中找到打字很重要.

财政支持总是受到欢迎,帮助我和该项目保持生命和健康.

所以,如果你可以, 如果这个项目以任何方式。 要么通过学习 要么只是帮助你 节省宝贵的时间, 请考虑捐赠.

## 许可证

这个项目将在 [MIT 许可证](https://npmcn.com/package/%40decaf-ts/utils/LICENSE.md)。 。 。 .

由开发者为开发者...

## 常见问题

### @decaf-ts/utils 是什么？

无咖啡因咖啡因的模块管理功用

### 如何安装 @decaf-ts/utils？

在项目目录运行 npm install @decaf-ts/utils，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 bundle、modules、run-all、npm-link、npm-token、build-docs、credentials、mirror-repo、tag-release、build-scripts、release-chain、compile-matrix，可以用 npx bundle 直接运行。

### @decaf-ts/utils 支持 TypeScript 吗？

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

### @decaf-ts/utils 支持 ESM 还是 CommonJS？

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

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

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

### @decaf-ts/utils 可以商用吗？

@decaf-ts/utils 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @decaf-ts/utils 的下载量有多少？

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

### @decaf-ts/utils 还在维护吗？

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

