https://github.com/compwright/split-human-name
Split a person's name into firstName and lastName fields
https://github.com/compwright/split-human-name
Last synced: 9 months ago
JSON representation
Split a person's name into firstName and lastName fields
- Host: GitHub
- URL: https://github.com/compwright/split-human-name
- Owner: compwright
- License: mit
- Created: 2018-09-20T12:21:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T12:55:34.000Z (over 1 year ago)
- Last Synced: 2025-04-13T11:50:08.381Z (9 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/split-human-name
- Size: 1.66 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# split-human-name
[](https://travis-ci.org/compwright/split-human-name)
[](https://david-dm.org/compwright/split-human-name)
[](https://www.npmjs.com/package/split-human-name)
[](https://github.com/sponsors/compwright)
Split a person's name into first name and last name fields
## Features
* Splits a name into exactly two fields `{ firstName, lastName }`
* Fixes UPPERCASE, lowercase, iNVERSE CASE, and otherwise FUnkY cAse
* Handles couples ("John and Jane Doe")
* Gracefully degrades to put the entire string in `firstName` if there are multiple last names
Based on the awesome [humanparser](https://www.npmjs.com/package/humanparser) and [namecase](https://www.npmjs.com/package/namecase) packages
Online demo: http://compwright.com/demos/split-human-name
## Requirements
* Node.js 10+
## Installation
```bash
$ npm install --save split-human-name
```
## Usage Examples
### Browser
```html
console.log(window.splitHumanName('John and Jane Doe'));
```
### Node
```javascript
const splitName = require('split-human-name');
const { firstName, lastName } = splitName('John and Jane Doe');
assert.strictEquals(firstName, 'John and Jane');
assert.strictEquals(lastName, 'Doe');
```
## License
MIT