Docs@skmtc/core

Names

FUNCTION

camelCase

@skmtc/core 0.63.4

Converts a string to camelCase, removing non-alphanumeric characters.

This function handles various input formats including kebab-case, snake_case, space-separated words, and mixed formats. It intelligently capitalizes words after the first unless upperFirst is specified.

Signature

import { camelCase } from '@skmtc/core'

camelCase(str: string, options?: CamelCaseOptions): string

Parameters

str, string required

The string to convert to camelCase

options, CamelCaseOptions

Options to control the conversion

upperFirst, boolean

Whether to capitalize the first character (PascalCase)

retainUnderscores, boolean

Whether to retain underscores in place when converting strings

Basic usage
camelCase('hello world'); // 'helloWorld'
camelCase('user-name'); // 'userName'
camelCase('api_key'); // 'apiKey'
camelCase('HTTP-Response'); // 'httpResponse'
PascalCase (upperFirst)
camelCase('user profile', { upperFirst: true }); // 'UserProfile'
camelCase('api-client', { upperFirst: true }); // 'ApiClient'
Complex inputs
camelCase('get-user-by-id'); // 'getUserById'
camelCase('XML_HTTP_Request'); // 'xmlHttpRequest'
camelCase('2fa-enabled'); // '2faEnabled'
Retaining underscores (retainUnderscores)
camelCase('user_name', { retainUnderscores: true }); // 'user_name'
camelCase('api-key_token', { retainUnderscores: true }); // 'apiKey_token'
camelCase('get_user_by_id', { retainUnderscores: true }); // 'get_user_by_id'
camelCase('user_profile', { upperFirst: true, retainUnderscores: true }); // 'User_profile'

Returns

string

The camelCase version of the input string