MCPcopy Create free account
hub / github.com/code-pushup/cli / toSentenceCase

Function toSentenceCase

packages/utils/src/lib/case-conversions.ts:87–97  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

85 * @returns The formatted sentence case string.
86 */
87export 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
99export function capitalize<T extends string>(text: T): Capitalize<T> {
100 return `${text.charAt(0).toUpperCase()}${text.slice(1).toLowerCase()}` as Capitalize<T>;

Callers 3

constants.tsFile · 0.90
logDiagnosticsSummaryFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected