Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ exports.parse = function(value) {
const name = {};
const tokens = value.match(/\S+/g) || [];

if (contains(salutations, tokens[0])) {
if (tokens[0] && contains(salutations, tokens[0])) {
name.salutation = tokens.shift();

// If there's only one token remaining it's the last name (Mister Rogers)
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ describe('Edge Cases', function() {
assert(name);
assert.strictEqual(Object.keys(name).length, 0);
});

it('single comma', function() {
let name = whosit.parse(',');
assert(name);
assert.strictEqual(Object.keys(name).length, 0);

name = whosit.parse(' , ');
assert(name);
assert.strictEqual(Object.keys(name).length, 0);
});
});

describe('Complex Surnames', function() {
Expand Down