From f88fdb0768ffc8d7767531e59d3eb9387d32689d Mon Sep 17 00:00:00 2001 From: "ivan.strahovsky" Date: Tue, 2 Feb 2021 11:40:47 -0600 Subject: [PATCH 1/4] #345 do not lowercase camel cased string --- lib/string-utils.ts | 7 ++++++- test/string-utils.cjs | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/string-utils.ts b/lib/string-utils.ts index 732e82a7..feb1b170 100644 --- a/lib/string-utils.ts +++ b/lib/string-utils.ts @@ -1,5 +1,10 @@ export function camelCase (str: string): string { - str = str.toLocaleLowerCase() + const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase(); + + if (!isCamelCase) { + str = str.toLocaleLowerCase(); + } + if (str.indexOf('-') === -1 && str.indexOf('_') === -1) { return str } else { diff --git a/test/string-utils.cjs b/test/string-utils.cjs index 1129777c..899b8bc2 100644 --- a/test/string-utils.cjs +++ b/test/string-utils.cjs @@ -11,6 +11,12 @@ describe('string-utils', function () { it('removes leading hyphens', () => { strictEqual(camelCase('-goodnight-moon'), 'goodnightMoon') }) + it('camelCase string stay as is', () => { + strictEqual(camelCase('iAmCamelCase'), 'iAmCamelCase') + }) + it('uppercase string with underscore to camel case', () => { + strictEqual(camelCase('NODE_VERSION'), 'nodeVersion') + }) }) describe('decamelize', () => { it('adds hyphens back to camelcase string', () => { From 3ba4e34c36312eb2aa964043e9f14cca6473e1c8 Mon Sep 17 00:00:00 2001 From: "ivan.strahovsky" Date: Tue, 2 Feb 2021 11:51:33 -0600 Subject: [PATCH 2/4] #345 fix style problems found by check script, remove extra continue which is redundun fot the last loop statement --- lib/string-utils.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/string-utils.ts b/lib/string-utils.ts index feb1b170..01588253 100644 --- a/lib/string-utils.ts +++ b/lib/string-utils.ts @@ -1,8 +1,8 @@ export function camelCase (str: string): string { - const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase(); + const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase() if (!isCamelCase) { - str = str.toLocaleLowerCase(); + str = str.toLocaleLowerCase() } if (str.indexOf('-') === -1 && str.indexOf('_') === -1) { @@ -19,7 +19,6 @@ export function camelCase (str: string): string { } if (i !== 0 && (chr === '-' || chr === '_')) { nextChrUpper = true - continue } else if (chr !== '-' && chr !== '_') { camelcase += chr } From 7f3dc52fe23e5eb45ec8619db0920dbdae0ffa7b Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Sat, 13 Feb 2021 11:33:36 -0800 Subject: [PATCH 3/4] Update test/string-utils.cjs --- test/string-utils.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/string-utils.cjs b/test/string-utils.cjs index 899b8bc2..74d618d4 100644 --- a/test/string-utils.cjs +++ b/test/string-utils.cjs @@ -11,7 +11,7 @@ describe('string-utils', function () { it('removes leading hyphens', () => { strictEqual(camelCase('-goodnight-moon'), 'goodnightMoon') }) - it('camelCase string stay as is', () => { + it('camelCase string stays as is', () => { strictEqual(camelCase('iAmCamelCase'), 'iAmCamelCase') }) it('uppercase string with underscore to camel case', () => { From 08546624985ab5741c7cbddd0fed0575b3bd8f43 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Sat, 13 Feb 2021 11:33:41 -0800 Subject: [PATCH 4/4] Update lib/string-utils.ts --- lib/string-utils.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/string-utils.ts b/lib/string-utils.ts index 01588253..16e73223 100644 --- a/lib/string-utils.ts +++ b/lib/string-utils.ts @@ -1,4 +1,6 @@ export function camelCase (str: string): string { + // Handle the case where an argument is provided as camel case, e.g., fooBar. + // by ensuring that the string isn't already mixed case: const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase() if (!isCamelCase) {