Skip to main content

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​

camelCase


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​

InputOutput
hello-worldHelloWorld
background_colorBackgroundColor
foo barFooBar
helloWorldHelloWorld

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'