Giter Site home page Giter Site logo

joshfraser / javascript-name-parser Goto Github PK

View Code? Open in Web Editor NEW
110.0 110.0 34.0 23 KB

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

Home Page: http://www.onlineaspect.com/2009/08/17/splitting-names/

JavaScript 75.17% HTML 24.83%

javascript-name-parser's People

Contributors

eljeffeg avatar joshfraser avatar medaro avatar mpemburn avatar retorquere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

javascript-name-parser's Issues

Handling Commas Before Suffixes

Thanks for a great parsing script--it's exactly what I needed for a project that I'm working on.

Physicians place a comma after their name and before their professional suffix as in John Smith, MD. parse-names.js is including this comma as part of the last name. One fix for this is to modify the trim function on line 24 to also remove commas.

return this.replace(/^\s+|\s+$|\,$/g,"");

Test suite

Google contacts has EXCELLENT name parsing for all languages.

https://www.google.com/contacts/#contacts

"API" at: https://clients6.google.com/plusi/v2/ozInternal/contactstoremutate?key=AIzaSyBuUpn1wi2-0JpM3S-tq2csYx0z2_m_pqc&alt=json

To illustrate: it knows that 诸葛亮 is last name 诸葛 and first name 亮, but it also knows that 柏夫人 is last name 柏 first name 夫人. This is done without language hinting, and it even recognizes the difference between Chinese and Japanese names, which could even use the same characters.


Although your library does not support it today, I request to add these and other examples to the test suite. The will fail, but it will demonstrate the scope and limits of this library.

remove dependency on browser-shims.js

the browser-shims.js file adds functions to some of the core classes of javascript. this make it unaccpetable to use the name parser library in a large project where we dont want a 3rd party lib to modify core behavior in any way.

if you reduce the dependency it will make the library acceptable to use in many, many more scenarios.

Overriding native trim string method

Modern browsers will already have the trim method, and you are overriding it with a slightly different replace. It's good practice to check for the existence before overriding it.

May I suggest:

if (!String.prototype.trim) {
  String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/gm, '');
  };
}

Suffixes with Multiple Periods Not Detected

Suffixes with multiple periods in them (such as M.D.) are not being detected by parse-names.js. For example, "John Smith, M.D." is parsed with "John Smith" as the first name and "M.D." as the last name. The fix for this is to modify line 141 to ignore all periods instead of just the first period.

word = word.replace(/\./g,"").toLowerCase();

Feature: Comma-Separated, Inverted Names | + Possible Bug

Hi there,

This is really useful!

In my use-case, it was necessary to first reverse the names if they appear to be LastName, FirstName.

The following is over-simplifying:

if(name.indexOf(',') !== -1)
{
    name = name.split(',')[1] + ' ' + name.split(',')[0];
}

Maybe something like this would be useful to have in the parser.

Also, maybe unrelated, the parser throws an error if there are too few characters. Could be solved as follows:

if(name.length < 3)
    return name;

Cheerio!

Middle names

Why does this library not support middle names?

p = NameParse.parse("Dr. Juan Quincy Adams Xavier de la Vega III")

I get:

firstName: "Juan Quincy Adams Xavier"
initials: ""
lastName: "De La Vega"
salutation: "Dr."
suffix: "III"

Seems like all names before initial/last name are first name? lol.

Bowerify?

Useful tool, would be cool to be able to install with bower.js

add professor to salutation

Hi,

maybe you could add to the

NameParse.is_salutation

function:

else if (word === "prof") {
		return "Prof."

Thank you !

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.