toCamelCase
Converts a string into camelCase format.> toCamelCase(str: string): string
- str (string): The input string to be converted into camelCase. Can include mixed cases, numbers, or delimiters (e.g., spaces, dashes, underscores).
- Returns: A string formatted in camelCase.
Example
import { toCamelCase } from "string-toolset";
// Convert a regular phrase to camelCase
console.log(toCamelCase("hello world")); // "helloWorld"
// Handle uppercase strings with delimiters
console.log(toCamelCase("HELLO-WORLD")); // "helloWorld"
// Convert snake_case to camelCase
console.log(toCamelCase("user_id")); // "userId"
// Handle kebab-case
console.log(toCamelCase("to-camel-case")); // "toCamelCase"
// Handle empty input
console.log(toCamelCase("")); // ""
Use Cases
- Converting strings for use as JavaScript variable names.
- Standardizing text inputs in camelCase format.
- Formatting user-provided strings for consistent handling in code.