This module provides a collection of utility functions for working with strings. It extends functionality from the Effect-TS library.

Basic String Operations

concat(self: string, that: string): string

Concatenates two strings together.
typescript
concat("Hello", " World") // returns "Hello World"

toUpperCase(self: string): string

Converts a string to uppercase.
typescript
toUpperCase("hello") // returns "HELLO"

toLowerCase(self: string): string

Converts a string to lowercase.
typescript
toLowerCase("HELLO") // returns "hello"

capitalize(self: string): string

Capitalizes the first character of a string.
typescript
capitalize("hello") // returns "Hello"

uncapitalize(self: string): string

Converts the first character of a string to lowercase.
typescript
uncapitalize("Hello") // returns "hello"

String Manipulation

replace(self: string, searchValue: string | RegExp, replaceValue: string): string

Replaces occurrences of a substring or pattern in a string.
typescript
replace("hello world", "world", "there") // returns "hello there"

trim(self: string): string

Removes whitespace from both ends of a string.
typescript
trim(" hello ") // returns "hello"

trimStart(self: string): string

Removes whitespace from the start of a string.
typescript
trimStart(" hello ") // returns "hello "

trimEnd(self: string): string

Removes whitespace from the end of a string.
typescript
trimEnd(" hello ") // returns " hello"

slice(self: string, start?: number, end?: number): string

Extracts a section of a string.
typescript
slice("hello world", 0, 5) // returns "hello"

String Checks

isEmpty(self: string): boolean

Tests whether a string is empty.
typescript
isEmpty("") // returns true isEmpty("hello") // returns false

isNonEmpty(self: string): boolean

Tests whether a string is non-empty.
typescript
isNonEmpty("hello") // returns true isNonEmpty("") // returns false

length(self: string): number

Calculates the length of a string.
typescript
length("hello") // returns 5

String Analysis

includes(self: string, searchString: string, position?: number): boolean

Checks if a string includes a substring.
typescript
includes("hello world", "world") // returns true

startsWith(self: string, searchString: string, position?: number): boolean

Checks if a string starts with a substring.
typescript
startsWith("hello world", "hello") // returns true

endsWith(self: string, searchString: string, position?: number): boolean

Checks if a string ends with a substring.
typescript
endsWith("hello world", "world") // returns true

String Transformations

split(self: string, separator: string | RegExp): string[]

Splits a string into an array of strings.
typescript
split("hello world", " ") // returns ["hello", "world"]

substring(self: string, start: number, end?: number): string

Extracts characters between two indices of a string.
typescript
substring("hello world", 0, 5) // returns "hello"

padStart(self: string, maxLength: number, fillString?: string): string

Pads the start of a string to reach a given length.
typescript
padStart("5", 2, "0") // returns "05"

padEnd(self: string, maxLength: number, fillString?: string): string

Pads the end of a string to reach a given length.
typescript
padEnd("5", 2, "0") // returns "50"

repeat(self: string, count: number): string

Repeats a string a specified number of times.
typescript
repeat("ha", 3) // returns "hahaha"

Case Conversions

snakeToCamel(self: string): string

Converts snake_case to camelCase.
typescript
snakeToCamel("hello_world") // returns "helloWorld"

snakeToPascal(self: string): string

Converts snake_case to PascalCase.
typescript
snakeToPascal("hello_world") // returns "HelloWorld"

snakeToKebab(self: string): string

Converts snake_case to kebab-case.
typescript
snakeToKebab("hello_world") // returns "hello-world"

camelToSnake(self: string): string

Converts camelCase to snake_case.
typescript
camelToSnake("helloWorld") // returns "hello_world"

pascalToSnake(self: string): string

Converts PascalCase to snake_case.
typescript
pascalToSnake("HelloWorld") // returns "hello_world"

kebabToSnake(self: string): string

Converts kebab-case to snake_case.
typescript
kebabToSnake("hello-world") // returns "hello_world"

Powered by Notaku