String
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.
concat("Hello", " World") // returns "Hello World" toUpperCase(self: string): string
Converts a string to uppercase.
toUpperCase("hello") // returns "HELLO" toLowerCase(self: string): string
Converts a string to lowercase.
toLowerCase("HELLO") // returns "hello" capitalize(self: string): string
Capitalizes the first character of a string.
capitalize("hello") // returns "Hello"uncapitalize(self: string): string
Converts the first character of a string to lowercase.
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.
replace("hello world", "world", "there") // returns "hello there" trim(self: string): string
Removes whitespace from both ends of a string.
trim(" hello ") // returns "hello" trimStart(self: string): string
Removes whitespace from the start of a string.
trimStart(" hello ") // returns "hello " trimEnd(self: string): string
Removes whitespace from the end of a string.
trimEnd(" hello ") // returns " hello" slice(self: string, start?: number, end?: number): string
Extracts a section of a string.
slice("hello world", 0, 5) // returns "hello" String Checks
isEmpty(self: string): boolean
Tests whether a string is empty.
isEmpty("") // returns true
isEmpty("hello") // returns false isNonEmpty(self: string): boolean
Tests whether a string is non-empty.
isNonEmpty("hello") // returns true
isNonEmpty("") // returns false length(self: string): number
Calculates the length of a string.
length("hello") // returns 5 String Analysis
includes(self: string, searchString: string, position?: number): boolean
Checks if a string includes a substring.
includes("hello world", "world") // returns true startsWith(self: string, searchString: string, position?: number): boolean
Checks if a string starts with a substring.
startsWith("hello world", "hello") // returns true endsWith(self: string, searchString: string, position?: number): boolean
Checks if a string ends with a substring.
endsWith("hello world", "world") // returns true String Transformations
split(self: string, separator: string | RegExp): string[]
Splits a string into an array of strings.
split("hello world", " ") // returns ["hello", "world"] substring(self: string, start: number, end?: number): string
Extracts characters between two indices of a string.
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.
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.
padEnd("5", 2, "0") // returns "50" repeat(self: string, count: number): string
Repeats a string a specified number of times.
repeat("ha", 3) // returns "hahaha" Case Conversions
snakeToCamel(self: string): string
Converts snake_case to camelCase.
snakeToCamel("hello_world") // returns "helloWorld" snakeToPascal(self: string): string
Converts snake_case to PascalCase.
snakeToPascal("hello_world") // returns "HelloWorld" snakeToKebab(self: string): string
Converts snake_case to kebab-case.
snakeToKebab("hello_world") // returns "hello-world" camelToSnake(self: string): string
Converts camelCase to snake_case.
camelToSnake("helloWorld") // returns "hello_world" pascalToSnake(self: string): string
Converts PascalCase to snake_case.
pascalToSnake("HelloWorld") // returns "hello_world" kebabToSnake(self: string): string
Converts kebab-case to snake_case.
kebabToSnake("hello-world") // returns "hello_world"