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.
typescriptconcat("Hello", " World") // returns "Hello World"
toUpperCase(self: string): string
Converts a string to uppercase.
typescripttoUpperCase("hello") // returns "HELLO"
toLowerCase(self: string): string
Converts a string to lowercase.
typescripttoLowerCase("HELLO") // returns "hello"
capitalize(self: string): string
Capitalizes the first character of a string.
typescriptcapitalize("hello") // returns "Hello"
uncapitalize(self: string): string
Converts the first character of a string to lowercase.
typescriptuncapitalize("Hello") // returns "hello"
String Manipulation
replace(self: string, searchValue: string | RegExp, replaceValue: string): string
Replaces occurrences of a substring or pattern in a string.
typescriptreplace("hello world", "world", "there") // returns "hello there"
trim(self: string): string
Removes whitespace from both ends of a string.
typescripttrim(" hello ") // returns "hello"
trimStart(self: string): string
Removes whitespace from the start of a string.
typescripttrimStart(" hello ") // returns "hello "
trimEnd(self: string): string
Removes whitespace from the end of a string.
typescripttrimEnd(" hello ") // returns " hello"
slice(self: string, start?: number, end?: number): string
Extracts a section of a string.
typescriptslice("hello world", 0, 5) // returns "hello"
String Checks
isEmpty(self: string): boolean
Tests whether a string is empty.
typescriptisEmpty("") // returns true isEmpty("hello") // returns false
isNonEmpty(self: string): boolean
Tests whether a string is non-empty.
typescriptisNonEmpty("hello") // returns true isNonEmpty("") // returns false
length(self: string): number
Calculates the length of a string.
typescriptlength("hello") // returns 5
String Analysis
includes(self: string, searchString: string, position?: number): boolean
Checks if a string includes a substring.
typescriptincludes("hello world", "world") // returns true
startsWith(self: string, searchString: string, position?: number): boolean
Checks if a string starts with a substring.
typescriptstartsWith("hello world", "hello") // returns true
endsWith(self: string, searchString: string, position?: number): boolean
Checks if a string ends with a substring.
typescriptendsWith("hello world", "world") // returns true
String Transformations
split(self: string, separator: string | RegExp): string[]
Splits a string into an array of strings.
typescriptsplit("hello world", " ") // returns ["hello", "world"]
substring(self: string, start: number, end?: number): string
Extracts characters between two indices of a string.
typescriptsubstring("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.
typescriptpadStart("5", 2, "0") // returns "05"
padEnd(self: string, maxLength: number, fillString?: string): string
Pads the end of a string to reach a given length.
typescriptpadEnd("5", 2, "0") // returns "50"
repeat(self: string, count: number): string
Repeats a string a specified number of times.
typescriptrepeat("ha", 3) // returns "hahaha"
Case Conversions
snakeToCamel(self: string): string
Converts snake_case to camelCase.
typescriptsnakeToCamel("hello_world") // returns "helloWorld"
snakeToPascal(self: string): string
Converts snake_case to PascalCase.
typescriptsnakeToPascal("hello_world") // returns "HelloWorld"
snakeToKebab(self: string): string
Converts snake_case to kebab-case.
typescriptsnakeToKebab("hello_world") // returns "hello-world"
camelToSnake(self: string): string
Converts camelCase to snake_case.
typescriptcamelToSnake("helloWorld") // returns "hello_world"
pascalToSnake(self: string): string
Converts PascalCase to snake_case.
typescriptpascalToSnake("HelloWorld") // returns "hello_world"
kebabToSnake(self: string): string
Converts kebab-case to snake_case.
typescriptkebabToSnake("hello-world") // returns "hello_world"