]> git.ardis.lu - csvio/commitdiff
Handle whitespace strings
authorArdis Lu <ardisglu@gmail.com>
Thu, 3 Jul 2025 06:45:31 +0000 (23:45 -0700)
committerArdis Lu <ardisglu@gmail.com>
Thu, 3 Jul 2025 06:45:31 +0000 (23:45 -0700)
src/normalization.js
test/normalization.test.js

index 04e24af4a88df17ca47ea57197a94de33820b4e0..a7409d453bcb2a4646a07b19dab3a47abb8ff2db 100644 (file)
@@ -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)}`;
   }
index e41a8762123ac0ef28f8365e56a49c82b94ba5da..c2c29ce4e0fb56570235a4c4e2d8980ac5fb19f4 100644 (file)
@@ -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 }, () => {
This page took 0.039745 seconds and 4 git commands to generate.