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