# @boringnode/pluralize 中文文档

规范地址：https://npmcn.com/package/%40boringnode/pluralize/

版本：0\.1\.0
npm 元数据更新时间：2025-12-30T23:20:15.902Z
中文译文更新时间：2026-11-08T11:43:27.867Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40boringnode/pluralize
原文对照：https://npmcn.com/package/%40boringnode/pluralize/?lang=original

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

- 包体积（解压后）：68.8 kB，12 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=20\.6
- 运行依赖：0 个
- 首次发布：2025-12-30T23:20:15.289Z
- 最新版本发布：2025-12-30T23:20:15.553Z
- 近 30 天下载量：11619（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 1 个）

## 中文简介

用于将英文单词复数和单数化的理论读取端口

## 安装

```sh
npm install @boringnode/pluralize
```

也可以使用：`pnpm add @boringnode/pluralize`、`yarn add @boringnode/pluralize`、`bun add @boringnode/pluralize`

## README

[![typescript-image](https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript)](https://www.typescriptlang.org/) [![npm-image](https://img.shields.io/npm/v/@boringnode/pluralize.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@boringnode/pluralize) [![npm-download-image](https://img.shields.io/npm/dm/@boringnode/pluralize?style=for-the-badge)](https://www.npmjs.com/package/@boringnode/pluralize) [![license-image](https://img.shields.io/npm/l/@boringnode/pluralize?color=blueviolet&style=for-the-badge)](https://npmcn.com/package/%40boringnode/pluralize/LICENSE.md)

`@boringnode/pluralize` 是多元化特性的 TypeScript 端口 [理论体现者](https://github.com/doctrine/inflector)。 。 。 .

内建支持:

-   **联合国** (单位:千美元)`en`, (中文(简体) ), `english`(中文(简体) )
-   **法语** (单位:千美元)`fr`, (中文(简体) ), `french`(中文(简体) )

> \[注\] 功能规则的修改(添加,去除,或修改规则)将不被视为断开修改.

## 安装

```sh
npm install @boringnode/pluralize
```

## 使用量

### 简单函数

使用库最简单的方式是具有简单的功能.

```ts
import { pluralize, singularize } from '@boringnode/pluralize'

pluralize('word') // 'words'
pluralize('person') // 'people'
pluralize('child') // 'children'

singularize('words') // 'word'
singularize('people') // 'person'
singularize('children') // 'child'
```

### 使用不同的区域

您可以创建 `Inflector` 使用不同语言.

```ts
import { Inflector } from '@boringnode/pluralize'

const inflector = new Inflector('fr')

inflector.pluralize('cheval')   // 'chevaux'
inflector.pluralize('bijou')    // 'bijoux'
inflector.singularize('chevaux') // 'cheval'
```

### 自定义规则, 带有缩写类

您可以创建 `Inflector` 实例以添加自定义规则.

```ts
import { Inflector } from '@boringnode/pluralize'

const inflector = new Inflector()
  .addIrregular('gex', 'gexes')
  .addUninflected('pokemon')
  .addPluralRule(/(.*)gon$/i, '$1gons')
  .addSingularRule(/(.*)gons$/i, '$1gon')

inflector.pluralize('gex') // 'gexes'
inflector.pluralize('pokemon') // 'pokemon'
inflector.singularize('dragons') // 'dragon'
```

### 创建自定义语言规则et

您可以为其它语言创建和注册自定义语言规则.

```ts
import { Inflector, type LanguageRuleset } from '@boringnode/pluralize'
import {
  pattern,
  Patterns,
  Substitutions,
  Transformations,
} from '@boringnode/pluralize/builder'

const SpanishRuleset: LanguageRuleset = {
  getSingularRuleset: () => ({
    regular: new Transformations([
      { pattern: pattern('es$'), replacement: '' },
      { pattern: pattern('s$'), replacement: '' },
    ]),
    uninflected: new Patterns([pattern('lunes'), pattern('martes')]),
    irregular: new Substitutions([{ from: 'hombres', to: 'hombre' }]),
  }),
  getPluralRuleset: () => ({
    regular: new Transformations([
      { pattern: pattern('[aeiou]$'), replacement: '$&s' },
      { pattern: pattern('$'), replacement: 'es' },
    ]),
    uninflected: new Patterns([pattern('lunes'), pattern('martes')]),
    irregular: new Substitutions([{ from: 'hombre', to: 'hombres' }]),
  }),
}

// Register the ruleset
Inflector.register('es', SpanishRuleset)

// Use it
const inflector = new Inflector('es')
inflector.pluralize('gato') // 'gatos'
```

## API 密码

### 职能

-   `pluralize(word: string): string` - 返回单词的复数形式
-   `singularize(word: string): string` - 返回单词的单数形式

### 缩写类

| 方法 | 说明 |
| --- | --- |
| `new Inflector(locale?: string)` | 创建新反射实例( 默认为 `'en'`(中文(简体) ) |
| `Inflector.register(locale, ruleset)` | 注册自定义语言规则et |
| `pluralize(word)` | 返回单词的复数形式 |
| `singularize(word)` | 返回单词的单数形式 |
| `addIrregular(singular, plural)` | 添加不规则单词映射 |
| `addUninflected(word)` | 添加单数和复数之间不变的单词 |
| `addPluralRule(pattern, replacement)` | 添加自定义复数化规则 |
| `addSingularRule(pattern, replacement)` | 添加自定义单数化规则 |

### 构建器导出( E)`@boringnode/pluralize/builder`(中文(简体) )

用于创建自定义语言规则:

| 导出 | 说明 |
| --- | --- |
| `pattern` | 创建大小写不敏感regex 的帮助器功能 |
| `Patterns` | 未反映文字的图案集 |
| `Transformation` | 接口 : `{ pattern: RegExp, replacement: string }` |
| `Transformations` | 一系列变换 |
| `Substitution` | 接口 : `{ from: string, to: string }` |
| `Substitutions` | 一组替代物 |
| `Ruleset` | 接口 : `{ regular, uninflected, irregular }` |

## 常见问题

### @boringnode/pluralize 是什么？

用于将英文单词复数和单数化的理论读取端口

### 如何安装 @boringnode/pluralize？

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

### @boringnode/pluralize 支持 TypeScript 吗？

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

### @boringnode/pluralize 支持 ESM 还是 CommonJS？

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

### @boringnode/pluralize 需要什么版本的 Node\.js？

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

### @boringnode/pluralize 可以商用吗？

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

### @boringnode/pluralize 的下载量有多少？

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

### @boringnode/pluralize 还在维护吗？

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

