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'