Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#345 do not lowercase camel cased string #348

Merged
merged 4 commits into from Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/string-utils.ts
@@ -1,5 +1,12 @@
export function camelCase (str: string): string {
str = str.toLocaleLowerCase()
// 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()
bcoe marked this conversation as resolved.
Show resolved Hide resolved

if (!isCamelCase) {
str = str.toLocaleLowerCase()
}

if (str.indexOf('-') === -1 && str.indexOf('_') === -1) {
return str
} else {
Expand All @@ -14,7 +21,6 @@ export function camelCase (str: string): string {
}
if (i !== 0 && (chr === '-' || chr === '_')) {
nextChrUpper = true
continue
} else if (chr !== '-' && chr !== '_') {
camelcase += chr
}
Expand Down
6 changes: 6 additions & 0 deletions test/string-utils.cjs
Expand Up @@ -11,6 +11,12 @@ describe('string-utils', function () {
it('removes leading hyphens', () => {
strictEqual(camelCase('-goodnight-moon'), 'goodnightMoon')
})
it('camelCase string stays 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', () => {
Expand Down