name-capitalize
v2.1.0
Published
Lightweight, zero-dependency utility for smart capitalization of person names. Optimized for Latin scripts, handling compound surnames, particles (de, del, la), and Unicode characters.
Maintainers
Readme
name-capitalize
Lightweight, zero-dependency utility for smart capitalization of person names. Handles particles (de, van, von…), hyphenated names, apostrophes, and Unicode characters.
Looking for the legacy version? See the
v1branch for Node 16 / Angular 12 compatibility (npm install name-capitalize@legacy).
Install
npm install name-capitalizeRequires Node 18 or higher.
Usage
import { capitalizeName } from 'name-capitalize';
capitalizeName('JUAN DE LA MAZA') // → 'Juan de la Maza'
capitalizeName('ludwig van beethoven') // → 'Ludwig van Beethoven'
capitalizeName("bernardo o'higgins") // → "Bernardo O'Higgins"
capitalizeName('JEAN-PIERRE DUPONT') // → 'Jean-Pierre Dupont'
capitalizeName('gabriel garcía márquez') // → 'Gabriel García Márquez'Behavior
- Particles (
de,del,van,von,di,da,bin…) stay lowercase unless they are the first word. - Multi-word particles (
van der,de la,de los…) are handled as a unit. - Words after a hyphen or apostrophe are always capitalized (
Jean-Pierre,O'Higgins). - Unicode letters are handled natively (
Ñ,Ö,Ş,Å…). - Leading/trailing whitespace is trimmed.
- Returns an empty string for empty, whitespace-only, or non-string input.
Changelog
See CHANGELOG.md.
License
MIT © Gabriel Galilea
