]> BookStack Code Mirror - bookstack/blob - resources/js/services/text.ts
Tests: Updated comment test to account for new editor usage
[bookstack] / resources / js / services / text.ts
1 /**
2  * Convert a kebab-case string to camelCase
3  */
4 export function kebabToCamel(kebab: string): string {
5     const ucFirst = (word: string) => word.slice(0, 1).toUpperCase() + word.slice(1);
6     const words = kebab.split('-');
7     return words[0] + words.slice(1).map(ucFirst).join('');
8 }
9
10 /**
11  * Convert a camelCase string to a kebab-case string.
12  */
13 export function camelToKebab(camelStr: string): string {
14     return camelStr.replace(/[A-Z]/g, (str, offset) => (offset > 0 ? '-' : '') + str.toLowerCase());
15 }