2022-11-28 07:12:36 -05:00
|
|
|
/**
|
|
|
|
* Convert a kebab-case string to camelCase
|
|
|
|
*/
|
2024-07-03 06:00:57 -04:00
|
|
|
export function kebabToCamel(kebab: string): string {
|
|
|
|
const ucFirst = (word: string) => word.slice(0, 1).toUpperCase() + word.slice(1);
|
2022-11-28 07:12:36 -05:00
|
|
|
const words = kebab.split('-');
|
|
|
|
return words[0] + words.slice(1).map(ucFirst).join('');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a camelCase string to a kebab-case string.
|
|
|
|
*/
|
2024-07-03 06:00:57 -04:00
|
|
|
export function camelToKebab(camelStr: string): string {
|
2023-04-18 17:20:02 -04:00
|
|
|
return camelStr.replace(/[A-Z]/g, (str, offset) => (offset > 0 ? '-' : '') + str.toLowerCase());
|
|
|
|
}
|