项目作者: chovy

项目描述 :
Parse a human name string into salutation, first name, middle name, last name, suffix.
高级语言: JavaScript
项目地址: git://github.com/chovy/humanparser.git
创建时间: 2014-05-26T05:50:57Z
项目社区:https://github.com/chovy/humanparser

开源协议:MIT License

下载


humanparser

NPM

Parse a human name string into salutation, first name, middle name, last name, suffix.

Install

  1. npm install humanparser

Usage

  1. const human = require('humanparser');

parse human name

  1. const fullName = 'Mr. William R. Hearst, III';
  2. const attrs = human.parseName(fullName);
  3. console.log(attrs);
  4. //produces the following output
  5. {
  6. salutation: 'Mr.',
  7. firstName: 'William',
  8. suffix: 'III',
  9. lastName: 'Hearst',
  10. middleName: 'R.',
  11. fullName: 'Mr. William R. Hearst, III'
  12. }

get fullest name in string

  1. const name = 'John & Peggy Sue';
  2. const fullName = human.getFullestName(name);
  3. //produces the following output
  4. {
  5. fullName: 'Peggy Sue'
  6. }

parse address

  1. const address = '123 Happy Street, Honolulu, HI 65780';
  2. const parsed = human.parseAddress(address);
  3. //produces the following output
  4. {
  5. address: '123 Happy Street',
  6. city: 'Honolulu',
  7. state: 'HI',
  8. zip: '65780',
  9. fullAddress: '123 Happy Street, Honolulu, HI 65780'
  10. }