Full Name Splitter
Human names are complicated. They don't necessarily follow any rules. Here's a good article about the complexities of names.
As that article advises, it's ideal to just store a user's full name, and not assume anything about the form the name takes.
However, there are times when it is necessary to have a split given name and family name. Such as when integrating with another system that made different design choices.
This package does a best-guess attempt to split a full name string into given name and family name. For many Western names, it will get it right. It knows about some common family name prefixes used in many European-language names, and initials. It removes salutations (Miss
, Doctor
, etc) and suffixes (III
, Jr
, etc).
Examples
; // => ["George H. W.", "Bush"] // => ["Kevin J.", "O'Connor"] // => ["Thomas G.", "Della Fave"] // => ["Gabriel", "Van Helsing"] // If full name isn't complete, it tries to split partially: // => ["George W.", null] // => ["George", null] // => [null, "Van Helsing"] // => [null, "d'Artagnan"]
For other examples see test/src/full-name-splitter.js
If it can't split a name correctly, it is possible to split by comma:
// => ["John Quincy", "Adams"] // => ["John", "Quincy Adams"]
Usage
The ES6 source (in src/
) is transpiled by Babel into lib/
in the npm prepublish
hook.
If you're not using this from npm, you'll need to manually trigger transpilation:
npm install && npm run prepublish
Copyright
Original Ruby version created by Pavel Gorbokon, with contributions by Michael S. Klishin and Trevor Creech.
This JavaScript port by Matt Dolan.
Released under the MIT license.