Skip to content

Str.Case

Str / Case

Import

typescript
import { Str } from '@wollybeard/kit'

// Access via namespace
Str.Case.someFunction()
typescript
import * as Str from '@wollybeard/kit/str'

// Access via namespace
Str.Case.someFunction()

Case Conversion

[F] constant

typescript
(name: string): string

Parameters:

  • name - The string to convert

Returns: The constant cased string

Convert string to CONSTANT_CASE (SCREAMING_SNAKE_CASE). Commonly used for environment variables and constants.

Examples:

typescript
Str
.Case.constant('helloWorld') // 'HELLO_WORLD'
Str
.Case.constant('foo-bar') // 'FOO_BAR'
Str
.Case.constant('myEnvVar') // 'MY_ENV_VAR'

[F] title

typescript
(str: string): string

Parameters:

  • str - The string to convert

Returns: The title cased string

Convert string to Title Case. Replaces hyphens and underscores with spaces and capitalizes the first letter of each word.

Examples:

typescript
Str
.Case.title('hello-world') // 'Hello World'
Str
.Case.title('foo_bar') // 'Foo Bar'
Str
.Case.title('the quick brown fox') // 'The Quick Brown Fox'

[F] capAll

typescript
<$S extends string>(str: $S): Uppercase<$S>

Parameters:

  • str - The string to convert

Returns: The uppercase string with Uppercase type

Convert string to UPPERCASE with type-level transformation. Preserves the uppercase type at the type level.

Examples:

typescript
uppercase('hello') // Type: "HELLO" (not string)
uppercase('world') // Type: "WORLD"

// Works with plain strings too
uppercase('hello world') // 'HELLO WORLD'
uppercase('FooBar') // 'FOOBAR'

[F] uncapFirst

typescript
<$S extends string>(s: $S): Uncapitalize<$S>

Parameters:

  • s - The string to convert

Returns: The string with lowercase first letter and Uncapitalize type

Convert the first letter of a string to lowercase with type-level transformation.

Examples:

typescript
lowerCaseFirst('Hello') // Type: "hello"
lowerCaseFirst('World') // Type: "world"
lowerCaseFirst('HELLO') // Type: "hELLO"

[F] capFirst

typescript
<$S extends string>(string: $S): Capitalize<$S>

Parameters:

  • string - The string to capitalize

Returns: The string with capitalized first letter and Capitalize type

Capitalize the first letter of a string with type-level transformation.

Examples:

typescript
capitalizeFirst('hello') // Type: "Hello"
capitalizeFirst('world') // Type: "World"
capitalizeFirst('foo bar') // Type: "Foo bar"

Other

[F] camel

typescript
(str: string): string
(str: string): string

Parameters:

  • str - The string that is to be changed to camel case.

Returns: string - The converted string to camel case.

Converts a string to camel case.

Camel case is the naming convention in which the first word is written in lowercase and each subsequent word begins with a capital letter, concatenated without any separator characters.

[F] kebab

typescript
(str: string): string
(str: string): string

Parameters:

  • str - The string that is to be changed to kebab case.

Returns: string - The converted string to kebab case.

Converts a string to kebab case.

Kebab case is the naming convention in which each word is written in lowercase and separated by a dash (-) character.

[F] pascal

typescript
(str: string): string
(str: string): string

Parameters:

  • str - The string that is to be changed to pascal case.

Returns: string - The converted string to Pascal case.

Converts a string to Pascal case.

Pascal case is the naming convention in which each word is capitalized and concatenated without any separator characters.

[F] snake

typescript
(str: string): string
(str: string): string

Parameters:

  • str - The string that is to be changed to snake case.

Returns: string - The converted string to snake case.

Converts a string to snake case.

Snake case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.