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

parse-lastname

v2.0.1

Published

Parse last names and extract suffixes (Jr, Sr, II, III, IV)

Readme

parse-lastname

A robust utility for parsing last names and extracting common suffixes (Jr, Sr, II, III, IV).

Installation

npm install parse-lastname

Usage

const { parseLastName } = require('parse-lastname');

// Basic usage
const result = parseLastName('Smith Jr');
console.log(result);
// Output: { lastName: 'Smith', suffix: 'Jr' }

// Without suffix
const result2 = parseLastName('Johnson');
console.log(result2);
// Output: { lastName: 'Johnson', suffix: null }

API

parseLastName(lastName)

Parses a last name, removes suffix, and returns both the cleaned last name and the suffix.

Parameters

  • lastName (string): The last name to process

Returns

An object with two properties:

  • lastName (string): The last name with suffix removed (or original if no suffix found)
  • suffix (string|null): The suffix that was removed, normalized to standard format (Jr, Sr, II, III, IV), or null if no suffix was found

Supported Suffixes

The function recognizes the following suffixes (case-insensitive, with or without periods):

  • Jr - Junior (also accepts: jr, JR, Jr., junior, Junior, JUNIOR)
  • Sr - Senior (also accepts: sr, SR, Sr., senior, Senior, SENIOR)
  • II - The Second (also accepts: ii, II.)
  • III - The Third (also accepts: iii, III.)
  • IV - The Fourth (also accepts: iv, IV.)

Features

  • Case-insensitive: Handles uppercase, lowercase, and mixed case
  • Flexible formatting: Works with or without periods
  • Smart matching: Only removes suffixes at the end of the name
  • Preserves middle content: Names like "McJronald" or "DeSrochers" remain unchanged
  • Handles spacing: Properly trims extra spaces
  • Robust edge cases: Handles empty strings, null, undefined, and non-string inputs

Examples

const parseLastName = require('parse-lastname');

// Jr variations
parseLastName('Smith Jr');
// { lastName: 'Smith', suffix: 'Jr' }

parseLastName('Johnson Jr.');
// { lastName: 'Johnson', suffix: 'Jr' }

parseLastName('Williams JUNIOR');
// { lastName: 'Williams', suffix: 'Jr' }

// Sr variations
parseLastName('Brown Sr');
// { lastName: 'Brown', suffix: 'Sr' }

parseLastName('Davis SR.');
// { lastName: 'Davis', suffix: 'Sr' }

// Roman numerals
parseLastName('Kennedy II');
// { lastName: 'Kennedy', suffix: 'II' }

parseLastName('Bush III');
// { lastName: 'Bush', suffix: 'III' }

parseLastName('Windsor IV');
// { lastName: 'Windsor', suffix: 'IV' }

// Complex names
parseLastName("O'Connor III");
// { lastName: "O'Connor", suffix: 'III' }

parseLastName('Van Buren Jr');
// { lastName: 'Van Buren', suffix: 'Jr' }

parseLastName('Smith-Johnson Sr');
// { lastName: 'Smith-Johnson', suffix: 'Sr' }

// No suffix
parseLastName('Anderson');
// { lastName: 'Anderson', suffix: null }

// Suffix in middle (not removed)
parseLastName('McJronald');
// { lastName: 'McJronald', suffix: null }

// Edge cases
parseLastName('Smith  Jr  ');
// { lastName: 'Smith', suffix: 'Jr' }

parseLastName('');
// { lastName: '', suffix: null }

Testing

The package includes 56 comprehensive test cases covering:

  • All suffix variations (Jr, Sr, II, III, IV)
  • Case sensitivity (uppercase, lowercase, mixed)
  • Period handling (with and without)
  • Spacing variations
  • Edge cases (empty, null, undefined, non-string)
  • Position testing (beginning, middle, end)
  • Complex real-world names (hyphenated, apostrophes, multi-word)

Run tests:

npm test

License

ISC