@compwright/namecase

中文文档
3.0.1发布于 2026/03/12ES Module零依赖近 30 天下载 3万

Module for fixing capitalization of people's names

原始使用文档
文档目录3 节
  1. Usage
  2. Code Example
  3. Command line

@compwright/namecase

A Javascript library for fixing the capitalization of people's names.

It is heavily based on the Perl Lingua-EN-NameCase module.

Version 3.x is now an ESM module and requires Node.js 20.x

Usage

namecase provides two functions:

checkName() which returns true if the name is in all UPPERCASE or lowercase.

namecase(string or array, { individualFields: boolean }) returns a properly capitalized name.

The option individualFields defaults to false which works best when the person's names are combined into a single field. If individualFields is set to true, it means you're passing in given and surnames separately. The only difference between these two options is with individualFields set to false, the first character is always capitalized.

Code Example

import { namecase } from '@compwright/namecase';
console.log(namecase('WILLIAM MCKINLEY'));

Command line

Namecase can also be executed from the command line via namecase, which accepts data from STDIN and outputs the formatted names to STDOUT.

$ npm install -g @compwright/namecase
$ echo "jonathon hill" | bin/namecase

版本与发布记录

@compwright/namecase 共发布 12 个版本,首次发布于 2018/09/20;过去 12 个月发布了 2 个版本。

版本发布日期距今
3.0.1latest2026/03/127 个月前
3.0.02025/11/1811 个月前
2.0.72024/11/092 年前
2.0.62020/12/175 年前
2.0.52020/09/096 年前
2.0.42020/09/096 年前

关于 @compwright/namecase 的常见问题

@compwright/namecase 是什么?

Module for fixing capitalization of people's names

如何安装 @compwright/namecase?

在项目目录运行 npm install @compwright/namecase,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 namecase,可以用 npx namecase 直接运行。

@compwright/namecase 支持 TypeScript 吗?

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

@compwright/namecase 支持 ESM 还是 CommonJS?

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

@compwright/namecase 需要什么版本的 Node.js?

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

@compwright/namecase 可以商用吗?

@compwright/namecase 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@compwright/namecase 的下载量有多少?

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

@compwright/namecase 还在维护吗?

最新版本 3.0.1 发布于 2026/03/12(7 个月前);至今共发布 12 个版本,其中过去 12 个月发布了 2 个;首次发布于 2018/09/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。