mikaelvesavuori/figmagic

View on GitHub
bin/frameworks/string/toPascalCase.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { ErrorToPascalCase } from '../errors/errors';

/**
 * @description Pascal-case transform a string
 */
export function toPascalCase(str: string): string {
  if (!str) throw Error(ErrorToPascalCase);

  return str
    .replace(/\w+/g, (w) => w[0].toUpperCase() + w.slice(1).toLowerCase())
    .replace(/\s+/g, '');
}