@foundernest/namecase

中文文档
1.0.5发布于 2021/06/16MITTypeScriptESM + CJS零依赖近 30 天下载 13.4万

A fully typed library for fixing capitalization of people's names. Based on tamtamchik PHP library.

原始使用文档
文档目录13 节
  1. Description
  2. Installation
  3. Usage
  4. Basic usage
  5. Advance usage
  6. Options
  7. Exclude Post-Nominals
  8. Changelog
  9. Testing
  10. Contributing
  11. Acknowledgements
  12. Credits
  13. License

NameCase

npm Build Status Coverage Status npm bundle size

NameCase is a fully typed implementation of Lingua::EN::NameCase, a library for converting strings to be properly cased. This is good for converting denormalized data to human friendly data.

Description

Forenames and surnames are often stored either entirely in UPPERCASE or lowercase. This library allows you to convert names into the correct case where possible. Although forenames and surnames are typically stored separately if they do appear in a single string, whitespace-separated, NameCase deals correctly with them.

Currently NameCase correctly name cases names which include any of the following:

Mc, Mac, al, el, ap, bat, ben, bin, binti, binte, da, de, das, dos, delle, della, di, du, del, der, den, ten, ter, la, le, lo, van and von.

It correctly deals with names which contain apostrophes and hyphens too.

Installation

Via npm

npm install @foundernest/namecase

Via yarn

yarn add @foundernest/namecase

Usage

Basic usage

import { nameCase } from '@foundernest/namecase';

nameCase('KEITH');               // => Keith
nameCase('LEIGH-WILLIAMS');      // => Leigh-Williams
nameCase('MCCARTHY');            // => McCarthy
nameCase("O'CALLAGHAN");         // => O'Callaghan
nameCase('ST. JOHN');            // => St. John
nameCase('VON STREIT');          // => von Streit
nameCase('AP LLWYD DAFYDD');     // => ap Llwyd Dafydd
nameCase('HENRY VIII');          // => Henry VIII
nameCase('VAN DYKE');            // => van Dyke

Advance usage

You can override the default options by calling the nameCase function with the EnvironmentOptions optional parameter:

import { nameCase } from '@foundernest/namecase';

nameCase('macmurdo');                        // => MacMurdo
nameCase('macmurdo', { irish: false });      // => Macmurdo

You can also set the options of all the subsequent calls:

import { nameCase, setOptions } from '@foundernest/namecase';

nameCase('macmurdo');               // => MacMurdo
setOptions({ irish: false });
nameCase('macmurdo');               // => Macmurdo

Or you can even create a new Environment object with custom options:

import Environment from '@foundernest/namecase';

const ncEnv = new Environment({
  lazy: false
  roman: false
});

ncEnv.nameCase('Na li');     // => Na Li

Options

  • lazy – Default: true. Do not do anything if string is already mixed case and lazy option is true.
  • irish – Default: true. Correct "Mac" exceptions.
  • spanish – Default: true. Correct spanish conjunctions y, e or i.
  • roman – Default: true. Correct roman numbers.
  • hebrew – Default: true. Correct ben, bat.
  • postnominal – Default: true. Correct post-nominal. e.g. PhD.

Exclude Post-Nominals

import { excludePostNominals, nameCase } from '@foundernest/namecase';

nameCase('ČERNÝ MOST');         // Černý MOst
excludePostNominals('MOst');
nameCase('ČERNÝ MOST');         // Černý Most

Changelog

Please see CHANGELOG for more information about what has changed recently.

Testing

yarn test

Contributing

Please see the Contributing guide and Code of Conduct for details.

Acknowledgements

This library is a port of the PHP package by Yuri Tkachenko which is also a port of the Perl library and owes most of its functionality to the Perl version by Mark Summerfield. Any bugs in the Typescript port are my fault.

Credits

Original PERL Lingua::EN::NameCase Version:

  • Copyright © Mark Summerfield 1998-2014. All Rights Reserved.
  • Copyright © Barbie 2014-2020. All Rights Reserved.

Ruby Version:

  • Copyright © Aaron Patterson 2006. All Rights Reserved.

PHP Version:

  • Copyright © Yuri Tkachenko 2016-2020. All Rights Reserved.

Typescript version:

License

The MIT License (MIT). Please see License File for more information.

版本与发布记录

@foundernest/namecase 共发布 14 个版本,首次发布于 2020/03/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.5latest2021/06/165 年前
1.0.42021/06/165 年前
1.0.32021/06/165 年前
1.0.22021/01/285 年前
1.0.12020/10/226 年前
1.0.02020/03/286 年前

关于 @foundernest/namecase 的常见问题

@foundernest/namecase 是什么?

A fully typed library for fixing capitalization of people's names. Based on tamtamchik PHP library.

如何安装 @foundernest/namecase?

在项目目录运行 npm install @foundernest/namecase,或使用 pnpm add / yarn add / bun add。

@foundernest/namecase 支持 TypeScript 吗?

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

@foundernest/namecase 支持 ESM 还是 CommonJS?

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

@foundernest/namecase 可以商用吗?

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

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

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

@foundernest/namecase 还在维护吗?

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