Kebab Case to Pascal Case

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
for loop
  const kebab = 'feaTure-name-VerY-long'
  if (!kebab) {
    return kebab;
  }
  const pieces = kebab.split('-').filter(piece => piece.length > 0);
  let formattedString = '';
  for (const piece of pieces) {
    if (piece.length > 0) {
      formattedString += piece[0].toUpperCase();
    }
    if (piece.length > 1) {
      formattedString += piece.slice(1).toLowerCase();
    }
  }
ready
map and join
  const kebab = 'feaTure-name-VerY-long'
  if (!kebab) {
    return kebab;
  }
  const pieces = kebab.split('-').filter(piece => piece.length > 0);
  return pieces
    .map(piece => {
      const chars = piece.split('');
      return chars.map((ch, index) => (index === 0 ? ch.toUpperCase() : ch.toLowerCase())).join('');
    })
    .join('');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.