parse-name
Parse a person's name into its component parts (title, first name, last name).
Last updated 6 years ago by ashaffer88 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install parse-name 
SYNC missed versions from official npm registry.

parse-name

Parses a human name into title, first, and last components.

Usage

parse

var parse = require('parse-name').parse;

user.name = parse('Mr. John Smith');
user.save();

compose

var compose = require('parse-name').compose;

var name = compose(user.name);
alert("Your name is " + name);

Options

  • respectful - use <title> <last> E.g. 'Mr. Smith'. Falls back to 'John Smith' if no title is present.
  • full - use <title> <first> <last> E.g. 'Mr. John Smith'. Any missing components will be left out

Example

var parse = require('parse-name').parse;

var name = parse('Mr. Smith');
assert.equal(name.title, 'Mr.');
assert.equal(name.first, '');
assert.equal(name.last, 'Smith');

name = parse('John Smith');
assert.equal(name.title, '');
assert.equal(name.first, 'John');
assert.equal(name.last, 'Smith');

name = parse('Mr. John Smith');
assert.equal(name.title, 'Mr.');
assert.equal(name.first, 'John');
assert.equal(name.last, 'Smith');

Custom Titles

var parse = require('parse-name').parse;

var name = parse('Prof. Smith', ['Prof.']);
assert.equal(name.title, 'Prof.');
assert.equal(name.first, '');
assert.equal(name.last, 'Smith');

Compose Name

var compose = require('parse-name').compose;

var components = {first: 'John', last: 'Smith', title: 'Mr.'};
assert.equal(compose(components), 'John Smith');
assert.equal(compose(components, {respectful: true}), 'Mr. Smith');

Current Tags

  • 0.2.4                                ...           latest (6 years ago)

6 Versions

  • 0.2.4                                ...           6 years ago
  • 0.2.3                                ...           6 years ago
  • 0.2.2                                ...           6 years ago
  • 0.2.1                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |