codetrix
Version:
A lightweight lodash-style utility library
15 lines (14 loc) • 368 B
JavaScript
/**
* Converts a string to camelCase format.
*
* @param str - The string to convert.
* @returns The camelCased string.
*
* @example
* camelCase('hello world'); // 'helloWorld'
*/
export function camelCase(str) {
return str
.replace(/[-_\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''))
.replace(/^[A-Z]/, (match) => match.toLowerCase());
}