From: Ardis Lu Date: Thu, 3 Jul 2025 06:45:31 +0000 (-0700) Subject: Handle whitespace strings X-Git-Tag: v0.1.2~8 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=e5397b2e6f0b9da1a9b837c6d3c7a32e86b6da99;p=csvio Handle whitespace strings --- 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 }, () => {