Skip to content

pascal

Converts a string to Pascal case format (first letter capitalized).

Syntax

typescript
pascal(str: string): string

Parameters

  • str (string): The string to convert

Return Value

  • string: String in Pascal case format

Examples

Basic Usage

typescript
import { pascal } from 'radash'

pascal('hello world') // 'HelloWorld'
pascal('hello-world') // 'HelloWorld'
pascal('hello_world') // 'HelloWorld'
pascal('Hello World') // 'HelloWorld'

Handling Various Delimiters

typescript
import { pascal } from 'radash'

pascal('user-name') // 'UserName'
pascal('user_name') // 'UserName'
pascal('user name') // 'UserName'
pascal('userName') // 'UserName'
pascal('UserName') // 'UserName'

Handling Special Characters

typescript
import { pascal } from 'radash'

pascal('first-name') // 'FirstName'
pascal('last_name') // 'LastName'
pascal('email address') // 'EmailAddress'
pascal('phone-number') // 'PhoneNumber'
pascal('date_of_birth') // 'DateOfBirth'

Handling Numbers

typescript
import { pascal } from 'radash'

pascal('user-123') // 'User123'
pascal('api-v2') // 'ApiV2'
pascal('version-1-0') // 'Version10'
pascal('test-123-abc') // 'Test123Abc'

Handling Abbreviations

typescript
import { pascal } from 'radash'

pascal('user-id') // 'UserId'
pascal('api-url') // 'ApiUrl'
pascal('http-request') // 'HttpRequest'
pascal('json-data') // 'JsonData'

Handling Consecutive Delimiters

typescript
import { pascal } from 'radash'

pascal('hello--world') // 'HelloWorld'
pascal('hello__world') // 'HelloWorld'
pascal('hello  world') // 'HelloWorld'
pascal('hello---world') // 'HelloWorld'

Handling Capitalized First Letters

typescript
import { pascal } from 'radash'

pascal('Hello World') // 'HelloWorld'
pascal('HELLO WORLD') // 'HelloWorld'
pascal('HelloWorld') // 'HelloWorld'
pascal('HELLO_WORLD') // 'HelloWorld'

Handling Empty Strings

typescript
import { pascal } from 'radash'

pascal('') // ''
pascal('   ') // ''
pascal('---') // ''
pascal('___') // ''

Handling Single Words

typescript
import { pascal } from 'radash'

pascal('hello') // 'Hello'
pascal('Hello') // 'Hello'
pascal('HELLO') // 'Hello'
pascal('world') // 'World'

Handling Complex Strings

typescript
import { pascal } from 'radash'

pascal('user-profile-settings') // 'UserProfileSettings'
pascal('api-endpoint-config') // 'ApiEndpointConfig'
pascal('database-connection-string') // 'DatabaseConnectionString'
pascal('http-request-handler') // 'HttpRequestHandler'

Handling Strings with Numbers

typescript
import { pascal } from 'radash'

pascal('user-123-profile') // 'User123Profile'
pascal('api-v2-endpoint') // 'ApiV2Endpoint'
pascal('test-1-2-3') // 'Test123'
pascal('version-1-0-0') // 'Version100'

Handling Special Symbols

typescript
import { pascal } from 'radash'

pascal('user@domain.com') // 'User@domain.com'
pascal('file-name.txt') // 'FileName.txt'
pascal('path/to/file') // 'Path/to/file'
pascal('query?param=value') // 'Query?param=value'

Handling Unicode Characters

typescript
import { pascal } from 'radash'

pascal('café-latte') // 'CaféLatte'
pascal('naïve-user') // 'NaïveUser'
pascal('résumé-data') // 'RésuméData'
pascal('über-user') // 'ÜberUser'

Handling Class Names and Component Names

typescript
import { pascal } from 'radash'

// React component names
pascal('user-profile') // 'UserProfile'
pascal('nav-bar') // 'NavBar'
pascal('side-menu') // 'SideMenu'

// CSS class names
pascal('btn-primary') // 'BtnPrimary'
pascal('card-header') // 'CardHeader'
pascal('dropdown-menu') // 'DropdownMenu'

Handling API Endpoints

typescript
import { pascal } from 'radash'

pascal('get-user-by-id') // 'GetUserById'
pascal('create-new-post') // 'CreateNewPost'
pascal('update-user-profile') // 'UpdateUserProfile'
pascal('delete-user-account') // 'DeleteUserAccount'

Handling Database Fields

typescript
import { pascal } from 'radash'

pascal('user_id') // 'UserId'
pascal('created_at') // 'CreatedAt'
pascal('updated_at') // 'UpdatedAt'
pascal('is_active') // 'IsActive'

Notes

  1. Capitalized First Letter: Pascal case always starts with a capital letter
  2. Delimiters: Supports spaces, hyphens, and underscores as delimiters
  3. Numbers: Numbers are preserved but not treated as delimiters
  4. Special Characters: Non-delimiter special characters are preserved

Differences from Other Functions

  • pascal: Converts to Pascal case (first letter capitalized)
  • camel: Converts to camel case (first letter lowercase)
  • snake: Converts to snake case
  • kebab: Converts to kebab case

Performance

  • Time Complexity: O(n), where n is the string length
  • Space Complexity: O(n)
  • Use Cases: Class names, component names, type name conversion

Released under the MIT License.