pascalCase()
pascalCase(
str):string
Converts a string to PascalCase.
note
Handles kebab-case, snake_case, camelCase, and space-separated strings.
Delegates word parsing to camelCase for consistency.
Parametersโ
str: stringโ
The string to convert.
Returns: stringโ
The string in PascalCase.
See Alsoโ
Sinceโ
2.0.0
Performanceโ
O(n) where n is string length. Single pass via camelCase + O(1) uppercase.
Also known asโ
pascal (Radashi) ยท pascalCase (es-toolkit, Modern Dash) ยท โ (Lodash, Remeda, Ramda, Effect, Antfu)
Exampleโ
pascalCase('hello-world'); // => 'HelloWorld'
pascalCase('background_color'); // => 'BackgroundColor'
pascalCase('foo bar'); // => 'FooBar'
pascalCase('helloWorld'); // => 'HelloWorld'
pascalCase('XMLHttpRequest'); // => 'XmlHttpRequest'
How it works?โ
Converts a string to PascalCase format. Each word capitalized, no separators.
Conversion Examplesโ
| Input | Output |
|---|---|
hello-world | HelloWorld |
background_color | BackgroundColor |
foo bar | FooBar |
helloWorld | HelloWorld |
Relationship with camelCaseโ
PascalCase = camelCase with first letter uppercase.
Use Casesโ
Generate component names ๐โ
Convert strings to PascalCase for React component names or class definitions.
Essential for scaffolding tools.
const component = pascalCase('nav_bar'); // 'NavBar'