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'