GithubHelp home page GithubHelp logo

dschnelldavis / parse-full-name Goto Github PK

View Code? Open in Web Editor NEW
74.0 74.0 15.0 18 KB

A function that accepts the full name of a person in any format, parses it, and returns its parts { title, first name, middle name, last name, nickname, suffix, [and any parsing errors] }.

JavaScript 100.00%

parse-full-name's People

Contributors

dschnelldavis avatar tcchau 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

parse-full-name's Issues

Not parsing properly when name has a dash (-).

The functions returns only last in case string is passed B05-1005
In my opinion, it should return return

{
  title: '',
  first: 'B05',
  middle: '-',
  last: '1005',
  nick: '',
  suffix: '',
  error: []
}

Also, is there a way we can choose which part to include in which case by passing preferences?

Single-digit Roman numeral suffixes parsed as last initial

This may be related to issue 11, NPM version not up to date.

When testing the names "Nicholas Runolfsdottir I" and "Nicholas Runolfsdottir V", I and V were output as last initials, respectively. II, III, and IV all work as intended (Runolfsdottir is output as last name).

I see V is on the list of suffixes in this repository, but have not had a chance to check if the latest version available here has the same issue. Regardless, the version downloaded from NPM does.

Typescript definitions

I'll just leave this here for now, until I can make a pull request to include the Typescript definitions.

declare module "parse-full-name" {
    export type PartToReturnSingle = "title" | "first" | "middle" | "last" | "nick" | "suffix" | "error";
    export type PartToReturnAll = "all" | undefined | null;
    export type FixCase = -1 | 0 | 1;

    export interface FullNameParsed {
        title: string;
        first: string;
        middle: string;
        last: string;
        nick: string;
        suffix: string;
        error: string[];
    }

    export function parseFullName(nameToParse: string, partToReturn: PartToReturnSingle, fixCase?: FixCase, stopOnError?: boolean, useLongLists?: boolean): string;
    export function parseFullName(nameToParse: string, partToReturn?: PartToReturnAll, fixCase?: FixCase, stopOnError?: boolean, useLongLists?: boolean): FullNameParsed;
    export function parseFullName(nameToParse: string, partToReturn?: PartToReturnAll | PartToReturnSingle, fixCase?: FixCase, stopOnError?: boolean, useLongLists?: boolean): string | FullNameParsed;
}

Two first names 'Marco Antonio Reyes Gonzalez'

The result is:

{
  title: '',
  first: 'Marco',
  middle: 'Antonio Reyes ',
  last: 'Gonzalez',
  nick: '',
  suffix: '',
  error: []
}

When it must be:

{
  title: '',
  first: 'Marco',
  middle: 'Antonio',
  last: 'Reyes Gonzalez',
  nick: '',
  suffix: '',
  error: []
}

Trouble with Dutch last names

Parsing for names like "Joe van den Berg" are returning 'Berg' as the last name. The last name should be "van den Berg".
Also tried "Joe Van Den Berg" but that did not help.
However, it is working for names similar like "Joe van der Berg".

"Van de Berg", "van den Berg" and "van der Berg" should probably all work -- they mean the same thing in general "from the mountain" and are very common Dutch surnames (see https://www.dutchgenealogy.nl/popular-dutch-surnames/).

Otherwise-- thanks much for what you have-- seems well documented and well thought out.

License

Not much explanation needed, I think. Does this code have a license?

Treating second nickname as last name

Example Input: 'Full Name [nickname1] (nickname2)'
Expected Result: {title: "", first: "FirstName", middle: "", last: "LastName", nick: "nickname1 nickname2", suffix: ""}
Actual Result: {title: "", first: "FirstName", middle: "LastName", last: "(nickname2)", nick: "nickname1", suffix: ""}

NPM version not up-to-date?

Hi,

I can see that in 7c5ada9 you've added a list of gender-neutral titles to the library, but the version on NPM doesn't appear to include those. Is there a way to reference the master version from GitHub, or could the NPM version be updated to include these?

Thanks! This is such a helpful library ๐Ÿ˜

Not parsing properly if there is no "space" after a "comma"

Parsing Smith,John
Results in {error: [], first: "John", last: "Smith", middle: "", nick: "", suffix: "", title: ""}

While parsing Smith,John
Results in {error: [], first: "", last: "Smith,John", middle: "", nick: "", suffix: "", title: ""}

The latter fails consistently regardless of the name if there is a "space" missing after the "comma" .

Just filing my discovery here, if anyone haves a clue if this is by design, or an actual bug - that would be pretty helpful. Thanks.

Duplicated values in titleList

parse-full-name/index.js

Lines 122 to 150 in a43097b

titleList = ['mr','mrs','ms','miss','dr','herr','monsieur','hr','frau',
'a v m','admiraal','admiral','air cdre','air commodore','air marshal',
'air vice marshal','alderman','alhaji','ambassador','baron','barones',
'brig','brig gen','brig general','brigadier','brigadier general',
'brother','canon','capt','captain','cardinal','cdr','chief','cik','cmdr',
'coach','col','col dr','colonel','commandant','commander','commissioner',
'commodore','comte','comtessa','congressman','conseiller','consul',
'conte','contessa','corporal','councillor','count','countess',
'crown prince','crown princess','dame','datin','dato','datuk',
'datuk seri','deacon','deaconess','dean','dhr','dipl ing','doctor',
'dott','dott sa','dr','dr ing','dra','drs','embajador','embajadora','en',
'encik','eng','eur ing','exma sra','exmo sr','f o','father',
'first lieutient','first officer','flt lieut','flying officer','fr',
'frau','fraulein','fru','gen','generaal','general','governor','graaf',
'gravin','group captain','grp capt','h e dr','h h','h m','h r h','hajah',
'haji','hajim','her highness','her majesty','herr','high chief',
'his highness','his holiness','his majesty','hon','hr','hra','ing','ir',
'jonkheer','judge','justice','khun ying','kolonel','lady','lcda','lic',
'lieut','lieut cdr','lieut col','lieut gen','lord','m','m l','m r',
'madame','mademoiselle','maj gen','major','master','mevrouw','miss',
'mlle','mme','monsieur','monsignor','mr','mrs','ms','mstr','nti','pastor',
'president','prince','princess','princesse','prinses','prof','prof dr',
'prof sir','professor','puan','puan sri','rabbi','rear admiral','rev',
'rev canon','rev dr','rev mother','reverend','rva','senator','sergeant',
'sheikh','sheikha','sig','sig na','sig ra','sir','sister','sqn ldr','sr',
'sr d','sra','srta','sultan','tan sri','tan sri dato','tengku','teuku',
'than puying','the hon dr','the hon justice','the hon miss','the hon mr',
'the hon mrs','the hon ms','the hon sir','the very rev','toh puan','tun',
'vice admiral','viscount','viscountess','wg cdr', 'ind', 'misc', 'mx'];

The titleList has a few duplicated values, like mr, ms, dr...

Is this a mistake or it is expected ?

Assume first name if only 1 word is entered

Thank you for this library. I really like the case-fixing that it provides.

When I call this library like parseFullName('steven'), the result is that steven is returned as the last name. This seems counterintuitive to me and should be returned as the first name.

Non-standerd syntax

Hi I'd like to keep using this in my web project, but your'e using Node syntax

Could you replace your first line with:
export function parseFullName(

Don't know if that works in Node.js, but it does work with my PWA project.

Last Name becomes Middle Name with trailing blankspace

a name such as Ezekiel Johnson would be fine as is and returns
{ title: '', first: 'Ezekiel', middle: '', last: 'Johnson', nick: '', suffix: '', error: [] }

but Ezekiel Johnson with a blank space at the end results in

{ title: '', first: 'Ezekiel', middle: 'Johnson', last: '', nick: '', suffix: '', error: [] }

Middle initials of "E" or "Y" results in incorrect interpretation

When a full name containing the middle initial "E" or "Y" is inputted into this module, the result is that the first, middle, and last name tokens are interpreted together as the last name.

Examples

input -> "Jimmie E French"
output -> {"title":"","first":"","middle":"","last":"Jimmie E French","nick":"","suffix":"","error":[]}

input -> "Brent Y Hickok II"
output -> {"title":"","first":"","middle":"","last":"Brent Y Hickok","nick":"","suffix":"II","error":[]}

Add support for Post-nominal letters

Currently, post-nominal letters (eg: M.D.) are treated like a suffix, however names often place a comma between the name, and the post-nominal letters. Here is an example:

John Doe III, M.D.

In this example, III is the suffix, and M.D. is the post-nominal letters. Since the syntax and placement are different, they should be parsed into separate fields.

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.