@kanton-basel-stadt/designsystem
Version:
Unplugin to install the digital design system of the canton of Basel-Stadt
14 lines (12 loc) • 371 B
text/typescript
export default function toPascalCase(input: string): string {
if (/^[A-Z][a-z]+(?:[A-Z][a-z]*)*$/.test(input)) {
return input // Already in PascalCase, return as-is
}
return input
.replace(/_/g, ' ')
.replace(/-/g, ' ')
.split(/\s+/)
.filter(Boolean)
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join('')
}