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 2 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
8 changes: 6 additions & 2 deletions 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()
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 +19,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 stay as is', () => {
bcoe marked this conversation as resolved.
Show resolved Hide resolved
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