Skip to content

Function: camelCase() ​

camelCase(input, options?): string

Convert a string of any case into camel case (userId). The words are found as noCase finds them: split at the characters other than letters and digits (spaces, _, -, .…, which are dropped) and at the case changes (fooBar, XMLHttp). The first word is in lower case, the others are capitalized and in lower case; a word starting with a digit is prefixed with _ (version_2Beta), so the words stay apart.

Parameters ​

input ​

string

The string to convert; an empty string, or one without letters nor digits, gives ''.

options? ​

NoCaseOptions

How the words are split and cased: separateNumbers also splits at the boundaries between letters and digits (version2beta is one word by default, version_2Beta with it); locale is the locale of the case conversions, the host's locale when undefined (a Turkish host lowers I to ı), and a locale-independent conversion when false.

Returns ​

string

The camel case string.

Example ​

typescript
import {camelCase} from 'lakutata/utils'

console.log(camelCase('user_id'), camelCase('XMLHttpRequest'), camelCase('version 2 beta', {locale: false}))
//userId xmlHttpRequest version_2Beta

Released under the MIT License.