# @curlconverter/yargs 中文文档

规范地址：https://npmcn.com/package/%40curlconverter/yargs/

版本：0\.0\.2
npm 元数据更新时间：2022-04-05T02:20:05.321Z
中文译文更新时间：2026-11-11T04:58:15.126Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：281 kB，59 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- Node.js 要求：\>=12
- 运行依赖：7 个
- 首次发布：2021-10-20T21:41:02.170Z
- 最新版本发布：2021-10-21T03:12:44.511Z
- 近 30 天下载量：68510（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

以海盗为主题的现代人 乐观主义者的接班人.

## 安装

```sh
npm install @curlconverter/yargs
```

也可以使用：`pnpm add @curlconverter/yargs`、`yarn add @curlconverter/yargs`、`bun add @curlconverter/yargs`

## README

![](https://raw.githubusercontent.com/yargs/yargs/main/yargs-logo.png)

# 驴子

**Yargs 是一个节点.js 库 fer hearties 尝试' ter 解析选择字符串**

  

![ci](https://github.com/yargs/yargs/workflows/ci/badge.svg) [![NPM version](https://img.shields.io/npm/v/yargs.svg)](https://www.npmjs.com/package/yargs) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![Coverage](https://img.shields.io/nycrc/yargs/yargs)](https://github.com/yargs/yargs/blob/main/.nycrc) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org/) [![Slack](http://devtoolscommunity.herokuapp.com/badge.svg)](http://devtoolscommunity.herokuapp.com/)

## 说明

Yargs帮助您构建交互式命令行工具,方法是解析参数并生成优雅的用户界面.

它给你:

-   命令和(分组)选项(`my-program.js serve --port=5000`) (中文(简体) ).
-   基于您参数的动态生成的帮助菜单 :

```
mocha [spec..]

Run tests with Mocha

Commands
  mocha inspect [spec..]  Run tests with Mocha                         [default]
  mocha init <path>       create a client-side Mocha setup at <path>

Rules & Behavior
  --allow-uncaught           Allow uncaught errors to propagate        [boolean]
  --async-only, -A           Require all tests to use a callback (async) or
                             return a Promise                          [boolean]
```

-   命令和选项的崩溃补全快捷键 .
-   财务报告和审定财务报表 [吨多一点](https://npmcn.com/docs/api.md)。 。 。 .

## 安装

稳定版本 :

```bash
npm i yargs
```

具有最新特性的出血边缘版本:

```bash
npm i yargs@next
```

## 使用量

### 简单示例

```javascript
#!/usr/bin/env node
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv

if (argv.ships > 3 && argv.distance < 53.5) {
  console.log('Plunder more riffiwobbles!')
} else {
  console.log('Retreat from the xupptumblers!')
}
```

```bash
$ ./plunder.js --ships=4 --distance=22
Plunder more riffiwobbles!

$ ./plunder.js --ships 12 --distance 98.7
Retreat from the xupptumblers!
```

> 说明: `hideBin` 是一个缩写 [`process.argv.slice(2)`](https://nodejs.org/en/knowledge/command-line/how-to-parse-command-line-arguments/)它的好处在于它考虑到某些环境中的差异,例如, [电子](https://github.com/electron/electron/issues/4690)。 。 。 .

### 复杂示例

```javascript
#!/usr/bin/env node
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')

yargs(hideBin(process.argv))
  .command('serve [port]', 'start the server', (yargs) => {
    return yargs
      .positional('port', {
        describe: 'port to bind on',
        default: 5000
      })
  }, (argv) => {
    if (argv.verbose) console.info(`start server on :${argv.port}`)
    serve(argv.port)
  })
  .option('verbose', {
    alias: 'v',
    type: 'boolean',
    description: 'Run with verbose logging'
  })
  .parse()
```

运行上面的示例 `--help` 以查看应用程序的帮助.

## 支持的平台

### 类型脚本

yargs 有类型定义 [@ types/ 亚尔格](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/main/types/yargs)。 。 。 .

```
npm i @types/yargs --save-dev
```

参见使用示例 [文档](https://npmcn.com/docs/typescript.md)。 。 。 .

### 德诺

截止 `v16`, (中文(简体) ), `yargs` 支持 [德诺](https://github.com/denoland/deno)数字 :

```typescript
import yargs from 'https://deno.land/x/yargs/deno.ts'
import { Arguments } from 'https://deno.land/x/yargs/deno-types.ts'

yargs(Deno.args)
  .command('download <files...>', 'download a list of files', (yargs: any) => {
    return yargs.positional('files', {
      describe: 'a list of files to do something with'
    })
  }, (argv: Arguments) => {
    console.info(argv)
  })
  .strictCommands()
  .demandCommand(1)
  .parse()
```

### 无害环境管理

截止 `v16`, (中文(简体) ),`yargs` 支持无害环境管理进口:

```js
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'

yargs(hideBin(process.argv))
  .command('curl <url>', 'fetch the contents of the URL', () => {}, (argv) => {
    console.info(argv)
  })
  .demandCommand(1)
  .parse()
```

### 浏览器中的用法

查看浏览器中使用 yargs 的例子 [文档](https://npmcn.com/docs/browser.md)。 。 。 .

## 社区

有问题吗? 想贡献吗? 加入我们的行列 [社区松懈](http://devtoolscommunity.herokuapp.com/)。 。 。 .

## 文档

### 目录

-   [亚尔格斯的API](https://npmcn.com/docs/api.md)
-   [实例](https://npmcn.com/docs/examples.md)
-   [解析策略](https://npmcn.com/docs/tricks.md)
    -   [停止解析器](https://npmcn.com/docs/tricks.md#stop)
    -   [提及布尔参数](https://npmcn.com/docs/tricks.md#negate)
    -   [数字](https://npmcn.com/docs/tricks.md#numbers)
    -   [阵列](https://npmcn.com/docs/tricks.md#arrays)
    -   [对象](https://npmcn.com/docs/tricks.md#objects)
    -   [引号](https://npmcn.com/docs/tricks.md#quotes)
-   [高级主题](https://npmcn.com/docs/advanced.md)
    -   [使用命令编译您的应用程序](https://npmcn.com/docs/advanced.md#commands)
    -   [构建可配置的 CLI 应用程序](https://npmcn.com/docs/advanced.md#configuration)
    -   [自定义 Yargs 解析器](https://npmcn.com/docs/advanced.md#customizing)
    -   [棉兰花](https://npmcn.com/docs/bundling.md)
-   [捐款](https://npmcn.com/contributing.md)

## 支持的节点.js版本

这一生态系统的图书馆尽最大努力追踪 [节点Js的发布时间表](https://nodejs.org/en/about/releases/)这里 [(单位:千美元) 贴上我们为什么认为 这很重要](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a)。 。 。 .

## 常见问题

### @curlconverter/yargs 是什么？

以海盗为主题的现代人 乐观主义者的接班人\.

### 如何安装 @curlconverter/yargs？

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

### @curlconverter/yargs 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/curlconverter\_\_yargs 是否存在。

### @curlconverter/yargs 支持 ESM 还是 CommonJS？

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

### @curlconverter/yargs 需要什么版本的 Node\.js？

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

### @curlconverter/yargs 可以商用吗？

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

### @curlconverter/yargs 的下载量有多少？

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

### @curlconverter/yargs 还在维护吗？

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

