Skip to content

Commit 8c6dba1

Browse files
committed
Update README.md
1 parent a274f7f commit 8c6dba1

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

README.md

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
JavaScript-Name-Parser
2-
======================
1+
JavaScript library to split names into their respective components (first, last, etc)
32

4-
JavaScript code to split names into their respective components (first, last, etc)
3+
**Usage:**
54

6-
Usage:
5+
var parser = new NameParse();
6+
var parsed = parser.parse("Mr. Chales P. Wooten, III");
77

8-
var parser = new NameParse();
9-
var parsed = parser.parse("Mr. Chales P. Wooten, III");
8+
**Results:**
109

11-
Results:
10+
parsed {
11+
salutation: "Mr.",
12+
firstName: "Charles",
13+
initials: "P",
14+
lastName: "Wooten",
15+
suffix: "III"
16+
}
1217

13-
parsed {
14-
salutation: "Mr.",
15-
firstName: "Charles",
16-
initials: "P",
17-
lastName: "Wooten",
18-
suffix: "III"
19-
}
20-
21-
The algorithm:
18+
**The algorithm:**
2219

2320
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.
2421

25-
Credits & license:
22+
**Credits & license:**
2623

27-
Based on [PHP Name Parser](http://www.onlineaspect.com/2009/08/17/splitting-names/) by [Josh Fraser](joshfraser.com)
28-
Ported to JavaScript by [Mark Pemburn](pemburnia.com)
29-
Released under Apache 2.0 license
24+
* Based on [PHP Name Parser](http://www.onlineaspect.com/2009/08/17/splitting-names/) by [Josh Fraser](http://joshfraser.com)
25+
* Ported to JavaScript by [Mark Pemburn](http://pemburnia.com)
26+
* Released under Apache 2.0 license

0 commit comments

Comments
 (0)