
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
parse-lastname
Advanced tools
A robust utility for parsing last names and extracting common suffixes (Jr, Sr, II, III, IV).
npm install parse-lastname
const { parseLastName, normalizeSuffix, isSuffix } = 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 }
parseLastName(lastName)Parses a last name, removes suffix, and returns both the cleaned last name and the suffix.
lastName (string): The last name to processAn 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 foundnormalizeSuffix(suffix)Normalizes a suffix string to its standard format.
suffix (string): The suffix to normalizeA normalized suffix string ('Jr', 'Sr', 'I', 'II', 'III', 'IV') or null if the input is not a recognized suffix.
normalizeSuffix('jr'); // 'Jr'
normalizeSuffix('JUNIOR'); // 'Jr'
normalizeSuffix('senior'); // 'Sr'
normalizeSuffix('iii'); // 'III'
normalizeSuffix('invalid'); // null
isSuffix(suffix)Checks if a string is a valid suffix.
suffix (string): The string to checktrue if the string is a recognized suffix, false otherwise.
isSuffix('Jr'); // true
isSuffix('jr'); // true
isSuffix('JUNIOR'); // true
isSuffix('III'); // true
isSuffix('Smith'); // false
isSuffix(''); // false
The function recognizes the following suffixes (case-insensitive, with or without periods):
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 }
The package includes 56 comprehensive test cases covering:
Run tests:
npm test
ISC
FAQs
Parse last names and extract suffixes (Jr, Sr, II, III, IV)
We found that parse-lastname demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.