Skip to content

strToCamelCase

Converts a string to camelCase: the first word is lowercased and every word after it gets an uppercase first letter, with all separators removed.

The string is split with words, so spaces, punctuation, - and _ all act as delimiters, camelCase boundaries split, an acronym stays whole (XMLHttpRequest becomes xmlHttpRequest) and a run of digits is its own word (abc12def becomes abc12Def).

Scripts without upper and lower case are passed through unchanged, so 한글English혼합 stays as it is.

This is the counterpart of strToPascalCase, strToSnakeCase, strToKebabCase and strToConstantCase. For a URL-friendly slug use getSlug instead, which is built for a different purpose.

Parameters

NameTypeRequiredDefault
textstringStringstr
The string to convert. An empty or missing value returns an empty string.

Returns

string

String

str

Examples

javascript
strToCamelCase('foo bar'); // Returns 'fooBar'
strToCamelCase('--foo-bar--'); // Returns 'fooBar'
strToCamelCase('__FOO_BAR__'); // Returns 'fooBar'
strToCamelCase('PascalCase'); // Returns 'pascalCase'
strToCamelCase('XMLHttpRequest'); // Returns 'xmlHttpRequest'
strToCamelCase('abc12def'); // Returns 'abc12Def'
dart
strToCamelCase('foo bar'); // Returns 'fooBar'
strToCamelCase('--foo-bar--'); // Returns 'fooBar'
strToCamelCase('__FOO_BAR__'); // Returns 'fooBar'
strToCamelCase('PascalCase'); // Returns 'pascalCase'
strToCamelCase('XMLHttpRequest'); // Returns 'xmlHttpRequest'
strToCamelCase('abc12def'); // Returns 'abc12Def'
python
strToCamelCase('foo bar')  # Returns 'fooBar'
strToCamelCase('--foo-bar--')  # Returns 'fooBar'
strToCamelCase('__FOO_BAR__')  # Returns 'fooBar'
strToCamelCase('PascalCase')  # Returns 'pascalCase'
strToCamelCase('XMLHttpRequest')  # Returns 'xmlHttpRequest'
strToCamelCase('abc12def')  # Returns 'abc12Def'

Released under the MIT License