To Pascal Case
utilcn/to-pascal-caseFreeUtility
Convert a string to PascalCase.
Install it
npx shadcn@latest add https://utilcn.dev/r/to-pascal-case.jsonSource
1/**2 * Converts a string to PascalCase.3 *4 * Handles acronyms properly, ensuring that something like5 * "XMLHttpRequest" becomes "XmlHttpRequest".6 *7 * @param str - The input string.8 * @returns The PascalCased string.9 *10 * @example11 * toPascalCase("hello world-example"); // "HelloWorldExample"12 * toPascalCase("XMLHttpRequest"); // "XmlHttpRequest"13 */14export function toPascalCase(str: string): string {15 return (16 str17 // Split acronym groups into proper boundaries18 .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')19 // Split between lowercase/digit and uppercase20 .replace(/([a-z\d])([A-Z])/g, '$1 $2')21 // Normalize spaces/underscores/dashes22 .replace(/[-_\s]+/g, ' ')23 // Lowercase all to normalize24 .toLowerCase()25 // Capitalize every word26 .replace(/\b\w/g, (c) => c.toUpperCase())27 // Remove spaces28 .replace(/\s+/g, '')29 );30}
Files it writes
More from utilcn
All 17 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Capitalizecapitalize | utilcn | Utilities | Free | no deps | |
| Capitalize Allcapitalize-all | utilcn | Utilities | Free | no deps | |
| Environment Server Configurationenv-server | utilcn | Utilities | Free | 1 dep | |
| Generate Presigned Download URLgenerate-presigned-download-url | utilcn | Utilities | Free | 2 deps · 2 files | |
| Generate Presigned Upload URLgenerate-presigned-upload-url | utilcn | Utilities | Free | 2 deps · 2 files | |
| Repeat Padrepeat-pad | utilcn | Utilities | Free | no deps | |
| Reverse Stringreverse-string | utilcn | Utilities | Free | no deps | |
| To Camel Caseto-camel-case | utilcn | Utilities | Free | no deps |
