joshfraser / javascript-name-parser Goto Github PK
View Code? Open in Web Editor NEWJavaScript code to split names into their respective components (first, last, etc)
Home Page: http://www.onlineaspect.com/2009/08/17/splitting-names/
JavaScript code to split names into their respective components (first, last, etc)
Home Page: http://www.onlineaspect.com/2009/08/17/splitting-names/
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,"");
Google contacts has EXCELLENT name parsing for all languages.
https://www.google.com/contacts/#contacts
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.
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.
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, '');
};
}
Jack Ma
is parsed as first name Jack and suffix MA, no last name.
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();
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!
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.
Useful tool, would be cool to be able to install with bower.js
Hi,
maybe you could add to the
NameParse.is_salutation
function:
else if (word === "prof") {
return "Prof."
Thank you !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.