From e5397b2e6f0b9da1a9b837c6d3c7a32e86b6da99 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 2 Jul 2025 23:45:31 -0700 Subject: [PATCH] Handle whitespace strings --- src/normalization.js | 1 + test/normalization.test.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/normalization.js b/src/normalization.js index 04e24af..a7409d4 100644 --- a/src/normalization.js +++ b/src/normalization.js @@ -20,6 +20,7 @@ export function getDecimalSeparator(locale) { */ export function toCamelCase(str) { str = str.trim(); + if (str === '') { return ''; } if (!/[\s\-_]+(.)/.test(str)) { // No separator found, fix the first letter but must assume the rest is already in camelCase return `${str[0].toLowerCase()}${str.substring(1)}`; } diff --git a/test/normalization.test.js b/test/normalization.test.js index e41a876..c2c29ce 100644 --- a/test/normalization.test.js +++ b/test/normalization.test.js @@ -45,7 +45,9 @@ suite('toCamelCase', { concurrency: true }, () => { { name: 'converts mixed casing', input: 'ExAmPlE oNe', output: 'exampleOne' }, { name: 'converts mixed casing (multiple words)', input: 'eXaMpLe TwO-wItH_mOrE wOrDs', output: 'exampleTwoWithMoreWords' }, { name: 'converts excess whitespace', input: ' exampleOne \r\n', output: 'exampleOne' }, - { name: 'converts excess whitespace (multiple words)', input: ' \r\n\r\n example Two\rWith More \r\nWords \r\n', output: 'exampleTwoWithMoreWords' } + { name: 'converts excess whitespace (multiple words)', input: ' \r\n\r\n example Two\rWith More \r\nWords \r\n', output: 'exampleTwoWithMoreWords' }, + { name: 'handles empty string', input: '', output: '' }, + { name: 'handles whitespace-only string', input: ' \r\n', output: '' } ]; for (const { name, input, output } of vectors) { test(name, { concurrency: true }, () => { -- 2.47.3