]> BookStack Code Mirror - bookstack/blob - resources/js/services/text.js
Connected md editor settings to logic for functionality
[bookstack] / resources / js / services / text.js
1 /**
2  * Convert a kebab-case string to camelCase
3  * @param {String} kebab
4  * @returns {string}
5  */
6 export function kebabToCamel(kebab) {
7     const ucFirst = (word) => word.slice(0,1).toUpperCase() + word.slice(1);
8     const words = kebab.split('-');
9     return words[0] + words.slice(1).map(ucFirst).join('');
10 }
11
12 /**
13  * Convert a camelCase string to a kebab-case string.
14  * @param {String} camelStr
15  * @returns {String}
16  */
17 export function camelToKebab(camelStr) {
18     return camelStr.replace(/[A-Z]/g, (str, offset) =>  (offset > 0 ? '-' : '') + str.toLowerCase());
19 }