JAVASCRIPT
Convert Kebab-Case String to CamelCase
Master transforming kebab-case strings, common in CSS and URLs, into camelCase format using a concise JavaScript regular expression pattern.
function kebabToCamelCase(kebabString) {
return kebabString.replace(/-(\w)/g, (match, p1) => p1.toUpperCase());
}
// Example usage:
const kebab = "my-component-name-example";
const camel = kebabToCamelCase(kebab); // "myComponentNameExample"
How it works: This JavaScript function uses a regular expression to find hyphens followed by any word character (`-(\w)`). For each match, it replaces the hyphen and the character with just the character in uppercase. This effectively converts a string from kebab-case (e.g., `font-size`) to camelCase (e.g., `fontSize`), which is highly useful for JavaScript variable names, object keys, or transforming CSS property names to DOM style properties.