camel
Convert a string to camel case format.
Syntax
typescript
camel(str: string): string
Parameters
str
(string): The string to convert
Return Value
string
: The string in camel case format
Examples
Basic Usage
typescript
import { camel } from 'radash'
camel('hello world') // 'helloWorld'
camel('hello-world') // 'helloWorld'
camel('hello_world') // 'helloWorld'
camel('Hello World') // 'helloWorld'
Handling Various Separators
typescript
import { camel } from 'radash'
camel('user-name') // 'userName'
camel('user_name') // 'userName'
camel('user name') // 'userName'
camel('userName') // 'userName'
camel('UserName') // 'userName'
Handling Special Characters
typescript
import { camel } from 'radash'
camel('first-name') // 'firstName'
camel('last_name') // 'lastName'
camel('email address') // 'emailAddress'
camel('phone-number') // 'phoneNumber'
camel('date_of_birth') // 'dateOfBirth'
Handling Numbers
typescript
import { camel } from 'radash'
camel('user-123') // 'user123'
camel('api-v2') // 'apiV2'
camel('version-1-0') // 'version10'
camel('test-123-abc') // 'test123Abc'
Handling Abbreviations
typescript
import { camel } from 'radash'
camel('user-id') // 'userId'
camel('api-url') // 'apiUrl'
camel('http-request') // 'httpRequest'
camel('json-data') // 'jsonData'
Handling Consecutive Separators
typescript
import { camel } from 'radash'
camel('hello--world') // 'helloWorld'
camel('hello__world') // 'helloWorld'
camel('hello world') // 'helloWorld'
camel('hello---world') // 'helloWorld'
Handling Capitalized First Letter
typescript
import { camel } from 'radash'
camel('Hello World') // 'helloWorld'
camel('HELLO WORLD') // 'helloWorld'
camel('HelloWorld') // 'helloWorld'
camel('HELLO_WORLD') // 'helloWorld'
Handling Empty String
typescript
import { camel } from 'radash'
camel('') // ''
camel(' ') // ''
camel('---') // ''
camel('___') // ''
Handling Single Word
typescript
import { camel } from 'radash'
camel('hello') // 'hello'
camel('Hello') // 'hello'
camel('HELLO') // 'hello'
camel('world') // 'world'
Handling Complex Strings
typescript
import { camel } from 'radash'
camel('user-profile-settings') // 'userProfileSettings'
camel('api-endpoint-config') // 'apiEndpointConfig'
camel('database-connection-string') // 'databaseConnectionString'
camel('http-request-handler') // 'httpRequestHandler'
Handling Strings with Numbers
typescript
import { camel } from 'radash'
camel('user-123-profile') // 'user123Profile'
camel('api-v2-endpoint') // 'apiV2Endpoint'
camel('test-1-2-3') // 'test123'
camel('version-1-0-0') // 'version100'
Handling Special Symbols
typescript
import { camel } from 'radash'
camel('user@domain.com') // 'user@domain.com'
camel('file-name.txt') // 'fileName.txt'
camel('path/to/file') // 'path/to/file'
camel('query?param=value') // 'query?param=value'
Handling Unicode Characters
typescript
import { camel } from 'radash'
camel('café-latte') // 'caféLatte'
camel('naïve-user') // 'naïveUser'
camel('résumé-data') // 'résuméData'
camel('über-user') // 'überUser'
Notes
- Lowercase First Letter: Camel case always starts with a lowercase letter
- Separators: Supports spaces, hyphens, and underscores as separators
- Numbers: Numbers are preserved but not treated as separators
- Special Characters: Non-separator special characters are preserved
Differences from Other Functions
camel
: Converts to camel case (lowercase first letter)pascal
: Converts to Pascal case (uppercase first letter)snake
: Converts to snake_casekebab
: Converts to kebab-case
Performance
- Time Complexity: O(n), where n is the string length
- Space Complexity: O(n)
- Use Cases: Variable naming, property name conversion