npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

person-name-parser

v1.0.4

Published

Utility that attempts to parse a person's name into its constituent parts, including a confidence rating of the output

Readme

Person Name Parser

npm version bundle size build status license

A lightweight utility that attempts to parses a person's full name into its constituent parts (prefix, first name, middle name, last name, suffix) with a confidence rating.

Features

  • Prefixes & suffixes: Parses titles (Dr., Prof.) and suffixes (Jr., PhD, III)
  • Initials: Groups consecutive initials intelligently (e.g., "T. S. Eliot")
  • Particles: Recognizes particles like "van", "von", "de", "da" for compound surnames
  • Nicknames: Removes nicknames in quotes or parentheses
  • Comma format: Supports "Last, First Middle" format
  • Confidence scoring: Returns a confidence rating for the parse result
  • Zero dependencies

Installation

npm install person-name-parser

Usage

Basic Example

import { parseName } from "person-name-parser";

const result = parseName("John Smith");
console.log(result);
// {
//   firstName: 'John',
//   lastName: 'Smith',
//   confidence: 1.0
// }

With All Name Parts

const result = parseName("Dr. Martin Luther King Jr");
console.log(result);
// {
//   prefix: 'Dr.',
//   firstName: 'Martin',
//   middleName: 'Luther',
//   lastName: 'King',
//   suffix: 'Jr',
//   confidence: 1.0
// }

Compound Surnames with Particles

const result = parseName("Ludwig van Beethoven");
console.log(result);
// {
//   firstName: 'Ludwig',
//   lastName: 'van Beethoven',
//   confidence: 1.0
// }

Initials

const result = parseName("T. S. Eliot");
console.log(result);
// {
//   firstName: 'T. S.',
//   lastName: 'Eliot',
//   confidence: 1.0
// }

Comma-Separated Format

const result = parseName("King, Martin Luther");
console.log(result);
// {
//   firstName: 'Martin',
//   middleName: 'Luther',
//   lastName: 'King',
//   confidence: 1.0
// }

Nicknames

const result = parseName('William "Bill" Gates');
console.log(result);
// {
//   firstName: 'William',
//   lastName: 'Gates',
//   confidence: 1.0
// }

Custom Options

You can provide custom sets of prefixes, suffixes, and particles:

const result = parseName("Sir Arthur Conan Doyle", {
  prefixes: new Set(["Sir", "Mr", "Mrs", "Dr", "Dr.", "Prof", "Prof."]),
  suffixes: new Set(["Jr", "Sr", "III", "PhD", "MD"]),
  particles: new Set(["van", "von", "de", "da", "del"]),
});

API Reference

parseName(fullName, options?)

Parses a full name string into its constituent parts.

Parameters:

  • fullName (string | null | undefined) - The full name to parse
  • options (ParseOptions, optional) - Parsing options

Returns: ParsedName

ParsedName

type ParsedName = {
  prefix?: string; // Title or honorific (Dr., Mr., Prof.)
  firstName?: string; // Given name
  middleName?: string; // Middle name(s)
  lastName?: string; // Surname/family name
  suffix?: string; // Generational or academic suffixes (Jr., PhD, III)
  confidence: number; // Confidence score (0-1)
};

ParseOptions

type ParseOptions = {
  prefixes?: Set<string>; // Custom set of recognized prefixes
  suffixes?: Set<string>; // Custom set of recognized suffixes
  particles?: Set<string>; // Custom set of surname particles
};

Confidence Score

The confidence score ranges from 0 to 1 and indicates how confident the parser is about the result:

  • 1.0 - High confidence (typical multi-part names with clear structure)
  • 0.5 - Medium confidence (single-word names)
  • 0.0 - No confidence (empty/invalid input)

The score is calculated based on:

  • Number of name tokens
  • Presence of recognizable prefixes and suffixes
  • Use of comma-separated format

Supported Name Patterns

  • Simple names: "John Smith"
  • Middle names: "John David Smith"
  • Multiple middle names: "John Paul George Ringo Starr"
  • Prefixes: "Dr. Jane Doe", "Professor Albert Einstein"
  • Suffixes: "Martin Luther King Jr", "William Gates III"
  • Multiple suffixes: "Robert Smith Jr, PhD"
  • Particles: "Ludwig van Beethoven", "Leonardo da Vinci"
  • Initials: "John F. Kennedy", "T. S. Eliot"
  • Nicknames: "William 'Bill' Gates", 'Robert "Bob" Smith'
  • Comma format: "Last, First Middle", "Last, Prefix First Middle Suffix"
  • Complex combinations: "Prof. Johann von Neumann PhD"

Limitations

This library is currently optimized for Western naming conventions and may not handle all global naming patterns accurately.

Current limitations:

  • Primarily designed for English/European name structures
  • May not correctly parse names from cultures with different conventions (e.g., Eastern Asian names where family name comes first, Arabic patronymics, etc.)
  • Limited support for non-Latin scripts
  • Assumes space-separated name components

Future improvements:

It would be good to make the parser configurable to support diverse cultural naming conventions, including:

  • Configurable name order (family-name-first vs. given-name-first)
  • Better support for non-Western particles and honorifics
  • Locale-aware parsing strategies
  • Support for mononyms and patronymic naming systems

Contributions and feedback are welcome to help improve support for diverse naming conventions!

Development

# Run tests
npm test

# Run tests with coverage
npm run test

# Build
npm run build

# Type check
npm run check

License

MIT License - Copyright 2025 Hyperfocal Group Ltd

See LICENSE.md for details.

Contributing

Issues and pull requests are welcome! Please feel free to contribute at github.com/hyperfocalHQ/person-name-parser.