(input: string)
| 85 | * @returns The formatted sentence case string. |
| 86 | */ |
| 87 | export function toSentenceCase(input: string): string { |
| 88 | return input |
| 89 | .replace(/([a-z])([A-Z])/g, '$1 $2') // Split PascalCase & camelCase |
| 90 | .replace(/[_-]/g, ' ') // Replace kebab-case and snake_case with spaces |
| 91 | .replace(/(\d+)/g, ' $1 ') // Add spaces around numbers |
| 92 | .replace(/\s+/g, ' ') // Remove extra spaces |
| 93 | .trim() |
| 94 | .toLowerCase() |
| 95 | .replace(/^(\w)/, match => match.toUpperCase()) // Capitalize first letter |
| 96 | .replace(/\b([A-Z]{2,})\b/g, match => match); // Preserve uppercase acronyms |
| 97 | } |
| 98 | |
| 99 | export function capitalize<T extends string>(text: T): Capitalize<T> { |
| 100 | return `${text.charAt(0).toUpperCase()}${text.slice(1).toLowerCase()}` as Capitalize<T>; |
no outgoing calls
no test coverage detected