Git Product home page Git Product logo

full-name-splitter's Introduction

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

import { splitter } from 'full-name-splitter';

splitter("George H. W. Bush")
// => ["George H. W.", "Bush"]

splitter("Kevin J. O'Connor")
// => ["Kevin J.", "O'Connor"]

splitter("Thomas G. Della Fave")
// => ["Thomas G.", "Della Fave"]

splitter("Gabriel Van Helsing")
// => ["Gabriel", "Van Helsing"]

// If full name isn't complete, it tries to split partially:

splitter("George W.")
// => ["George W.", null]

splitter("George")
// => ["George", null]

splitter("Van Helsing")
// => [null, "Van Helsing"]

splitter("d'Artagnan")
// => [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:

splitter("John Quincy Adams")
// => ["John Quincy", "Adams"]

splitter("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.

full-name-splitter's People

Contributors

mgduk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.