JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<body>
<div class="output">
</div>
</body>
</html>
Babel + JSX
const toCamel = (s) => {
return s.replace(/([-_][a-z])/ig, ($1) => {
return $1.toUpperCase()
.replace('-', '')
.replace('_', '');
});
};
const kt1 = 'shish-kebab';
const kt2 = 'with-rice-and-naan';
const kt3 = 'kabob';
const kt4 = 'kabob-Stuff';
const kt5 = 'kabob_';
const st1 = 'he_who_shall_not_be_named';
const st2 = 'lord_voldemort';
const st3 = 'nagini';
const output = document.querySelector('.output');
const write = (t) => {
const p = document.createElement('p');
const txt = document.createTextNode(t);
p.appendChild(txt);
output.appendChild(p);
};
write('testing...');
write(`${kt1}: ${toCamel(kt1)}`);
write(`${kt2}: ${toCamel(kt2)}`);
write(`${kt3}: ${toCamel(kt3)}`);
write(`${kt4}: ${toCamel(kt4)}`);
write(`${kt5}: ${toCamel(kt5)}`);
write(`${st1}: ${toCamel(st1)}`);
write(`${st2}: ${toCamel(st2)}`);
write(`${st3}: ${toCamel(st3)}`);