Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@foundernest/namecase

foundernest26kMIT1.0.5TypeScript support: included

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

name-case, namecase, name, capitalization, names, case, internationalization

readme

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.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

Changed

  • Update travis-ci URL after migration.
  • Update Code of conduct file

1.0.2 - 2021-01-28

Changed

  • Bump dependencies

1.0.1 - 2020-10-21

Changed

  • Fixed problems with RegExp in Safari

1.0.0 - 2020-03-27

Added

  • New README content with installation instructions and extra documentation.
  • Husky and lint-staged to format code before every commit.
  • Code of conduct file
  • Contributing file

Changed

  • Avoid automatic formatting of .md files
  • Update License year

0.1.0 - 2020-03-11

Initial release