From a1cd44369785de589b32009f59f36a60623813d7 Mon Sep 17 00:00:00 2001 From: Shawn Miller Date: Tue, 20 May 2025 09:42:58 -0500 Subject: [PATCH] add test for single comma --- lib/index.js | 2 +- test/test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 07f80e3..c06b8ab 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) diff --git a/test/test.js b/test/test.js index 649ca24..ad1bc48 100644 --- a/test/test.js +++ b/test/test.js @@ -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() {