Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

humanname

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

humanname

A human name parser for nodejs. Parses names an split them up into parts

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
861
decreased by-59.12%
Maintainers
1
Weekly downloads
 
Created
Source

humanname

JavaScript library to split names into their respective components (first, last, etc)

Usage:

    // in browser
    var parser = new NameParse();
    var parsed = parser.parse("Mr. Chales P. Wooten, III");
    // in nodejs
    var humanname = require('humanname');
    var parsed = humanname.parse("Mr. Chales P. Wooten, III");

Results:

parsed { 
    salutation: "Mr.", 
    firstName: "Charles", 
    initials: "P", 
    lastName: "Wooten", 
    suffix: "III" 
}

The algorithm:

We start by splitting the full name into separate words. We then do a dictionary lookup on the first and last words to see if they are a common prefix or suffix. Next, we take the middle portion of the string (everything minus the prefix & suffix) and look at everything except the last word of that string. We then loop through each of those words concatenating them together to make up the first name. While we’re doing that, we watch for any indication of a compound last name. It turns out that almost every compound last name starts with 1 of 15 prefixes (Von, Van, Vere, etc). If we see one of those prefixes, we break out of the first name loop and move on to concatenating the last name. We handle the capitalization issue by checking for camel-case before uppercasing the first letter of each word and lowercasing everything else. I wrote special cases for periods and dashes. We also have a couple other special cases, like ignoring words in parentheses all-together.

Credits & license:

  • Based on PHP Name Parser by Josh Fraser
  • Ported to JavaScript by Mark Pemburn
  • Adapted for Nodejs by Christoph Hartmann

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Keywords

FAQs

Package last updated on 29 May 2014

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc