String
This module provides utility functions and type class instances for working with the string type in TypeScript. It includes functions for basic string manipulation, as well as type class instances for Equivalence and Order.
Guards
Instances
Equivalence
Signature
declare const Equivalence: equivalence.Equivalence<string>;Signature
declare const Order: order.Order<string>;Other
Signature
declare const at: {
(index: number): (self: string) => Option<string>;
(self: string, index: number): Option<string>;
};Example
import * as assert from "node:assert"
import { pipe, String, Option } from "effect"
assert.deepStrictEqual(pipe("abc", String.at(1)), Option.some("b"))
assert.deepStrictEqual(pipe("abc", String.at(4)), Option.none())camelToSnake
Signature
declare function camelToSnake(self: string): string;capitalize
Signature
declare function capitalize<T extends string>(self: T): Capitalize<T>;Signature
declare const charAt: {
(index: number): (self: string) => Option<string>;
(self: string, index: number): Option<string>;
};Example
import * as assert from "node:assert"
import { pipe, String, Option } from "effect"
assert.deepStrictEqual(pipe("abc", String.charAt(1)), Option.some("b"))
assert.deepStrictEqual(pipe("abc", String.charAt(4)), Option.none())charCodeAt
Signature
declare const charCodeAt: {
(index: number): (self: string) => Option<number>;
(self: string, index: number): Option<number>;
};Example
import * as assert from "node:assert"
import { pipe, String, Option } from "effect"
assert.deepStrictEqual(pipe("abc", String.charCodeAt(1)), Option.some(98))
assert.deepStrictEqual(pipe("abc", String.charCodeAt(4)), Option.none())codePointAt
Signature
declare const codePointAt: {
(index: number): (self: string) => Option<number>;
(self: string, index: number): Option<number>;
};Example
import * as assert from "node:assert"
import { pipe, String, Option } from "effect"
assert.deepStrictEqual(pipe("abc", String.codePointAt(1)), Option.some(98))Concatenates two strings at runtime.
Signature
declare const concat: {
<B extends string>(that: B): <A extends string>(self: A) => `${A}${B}`;
<A extends string, B extends string>(self: A, that: B): `${A}${B}`;
};Concatenates two strings at the type level.
Signature
type Concat<A extends string, B extends string> = `${A}${B}`;The empty string "".
Signature
declare const empty: "";Signature
declare function endsWith(searchString: string, position?: number): (self: string) => boolean;Returns true if searchString appears as a substring of self, at one or more positions that are greater than or equal to position; otherwise, returns false.
Signature
declare function includes(searchString: string, position?: number): (self: string) => boolean;Signature
declare function indexOf(searchString: string): (self: string) => Option<number>;Test whether a string is empty.
Signature
declare function isEmpty(self: string): self is "";isNonEmpty
Test whether a string is non empty.
Signature
declare function isNonEmpty(self: string): boolean;kebabToSnake
Signature
declare function kebabToSnake(self: string): string;lastIndexOf
Signature
declare function lastIndexOf(searchString: string): (self: string) => Option<number>;Calculate the number of characters in a string.
Signature
declare function length(self: string): number;linesIterator
Returns an IterableIterator which yields each line contained within the string, trimming off the trailing newline character.
Signature
declare function linesIterator(self: string): LinesIterator;linesWithSeparators
Returns an IterableIterator which yields each line contained within the string as well as the trailing newline character.
Signature
declare function linesWithSeparators(s: string): LinesIterator;localeCompare
Signature
declare function localeCompare(
that: string,
locales?: LocalesArgument,
options?: CollatorOptions,
): (self: string) => Ordering;It is the pipe-able version of the native match method.
Signature
declare function match(regexp: string | RegExp): (self: string) => Option<RegExpMatchArray>;It is the pipe-able version of the native matchAll method.
Signature
declare function matchAll(regexp: RegExp): (self: string) => IterableIterator<RegExpMatchArray>;Signature
declare function normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD"): (self: string) => string;Signature
declare function padEnd(maxLength: number, fillString?: string): (self: string) => string;Signature
declare function padStart(maxLength: number, fillString?: string): (self: string) => string;pascalToSnake
Signature
declare function pascalToSnake(self: string): string;Signature
declare function repeat(count: number): (self: string) => string;Signature
declare function replace(
searchValue: string | RegExp,
replaceValue: string,
): (self: string) => string;replaceAll
Signature
declare function replaceAll(
searchValue: string | RegExp,
replaceValue: string,
): (self: string) => string;Signature
declare const search: {
(regexp: string | RegExp): (self: string) => Option<number>;
(self: string, regexp: string | RegExp): Option<number>;
};Example
import * as assert from "node:assert"
import { pipe, String, Option } from "effect"
assert.deepStrictEqual(pipe("ababb", String.search("b")), Option.some(1))
assert.deepStrictEqual(pipe("ababb", String.search(/abb/)), Option.some(2))
assert.deepStrictEqual(pipe("ababb", String.search("d")), Option.none())Signature
declare function slice(start?: number, end?: number): (self: string) => string;snakeToCamel
Signature
declare function snakeToCamel(self: string): string;snakeToKebab
Signature
declare function snakeToKebab(self: string): string;snakeToPascal
Signature
declare function snakeToPascal(self: string): string;Signature
declare const split: {
(separator: string | RegExp): (self: string) => [string, ...Array<string>];
(self: string, separator: string | RegExp): [string, ...Array<string>];
};Example
import * as assert from "node:assert"
import { pipe, String } from "effect"
assert.deepStrictEqual(pipe("abc", String.split("")), ["a", "b", "c"])
assert.deepStrictEqual(pipe("", String.split("")), [""])startsWith
Signature
declare function startsWith(searchString: string, position?: number): (self: string) => boolean;stripMargin
For every line in this string, strip a leading prefix consisting of blanks or control characters followed by the "|" character from the line.
Signature
declare function stripMargin(self: string): string;stripMarginWith
For every line in this string, strip a leading prefix consisting of blanks or control characters followed by the character specified by marginChar from the line.
Signature
declare const stripMarginWith: {
(marginChar: string): (self: string) => string;
(self: string, marginChar: string): string;
};Signature
declare function substring(start: number, end?: number): (self: string) => string;Keep the specified number of characters from the start of a string.
If n is larger than the available number of characters, the string will be returned whole.
If n is not a positive number, an empty string will be returned.
If n is a float, it will be rounded down to the nearest integer.
Signature
declare const takeLeft: {
(n: number): (self: string) => string;
(self: string, n: number): string;
};Example
import * as assert from "node:assert"
import { String } from "effect"
assert.deepStrictEqual(String.takeLeft("Hello World", 5), "Hello")Keep the specified number of characters from the end of a string.
If n is larger than the available number of characters, the string will be returned whole.
If n is not a positive number, an empty string will be returned.
If n is a float, it will be rounded down to the nearest integer.
Signature
declare const takeRight: {
(n: number): (self: string) => string;
(self: string, n: number): string;
};Example
import * as assert from "node:assert"
import { String } from "effect"
assert.deepStrictEqual(String.takeRight("Hello World", 5), "World")toLocaleLowerCase
Signature
declare function toLocaleLowerCase(locale?: LocalesArgument): (self: string) => string;toLocaleUpperCase
Signature
declare function toLocaleUpperCase(locale?: LocalesArgument): (self: string) => string;toLowerCase
Signature
declare function toLowerCase<T extends string>(self: T): Lowercase<T>;toUpperCase
Signature
declare function toUpperCase<S extends string>(self: S): Uppercase<S>;Signature
declare function trim<A extends string>(self: A): TrimEnd<TrimStart<A>>;Signature
type Trim<A extends string> = TrimEnd<TrimStart<A>>;Signature
declare function trimEnd<A extends string>(self: A): TrimEnd<A>;Signature
type TrimEnd<A extends string> = A extends `${infer B}${" " | "\n" | "\t" | "\r"}` ? TrimEnd<B> : A;Signature
declare function trimStart<A extends string>(self: A): TrimStart<A>;Signature
type TrimStart<A extends string> = A extends `${" " | "\n" | "\t" | "\r"}${infer B}`
? TrimStart<B>
: A;uncapitalize
Signature
declare function uncapitalize<T extends string>(self: T): Uncapitalize<T>;
Tests if a value is a
string.