string
extract
ExtractIfStartsWith
type ExtractIfStartsWith<T extends string, P extends string>Extracts from a union of strings those that start with a given prefix.
type Keys = KeyofDeep<Config>; // 'defaults.a' | 'defaults.b' | 'messages.error' | 'messages.success'
type R1 = ExtractIfStartsWith<Keys, 'defaults'>; // 'defaults.a' | 'defaults.b'
type R2 = ExtractIfStartsWith<Keys, 'messages'>; // 'messages.error' | 'messages.success'ExtractIfEndsWith
type ExtractIfEndsWith<T extends string, P extends string>Extracts from a union of strings those that end with a given suffix.
ExtractIfContains
type ExtractIfContains<
T extends string,
P extends string,
>Extracts from a union of strings those that contain a given substring.
ExcludeIfStartsWith
type ExcludeIfStartsWith<T extends string, S extends string>Excludes from a union of strings those that start with a given prefix.
ExcludeIfEndsWith
type ExcludeIfEndsWith<T extends string, S extends string>Excludes from a union of strings those that end with a given suffix.
ExcludeIfContains
type ExcludeIfContains<
T extends string,
S extends string,
>Excludes from a union of strings those that contain a given substring.
firstChar
FirstChar
type FirstChar<T extends string>Returns the first character in a given string.
LastChar
type LastChar<T extends string>Returns the last character in a given string.
This type will run T["length"] times to reach the last character.
prefix
Prefix
type Prefix<T extends string, P extends string>Adds a prefix to a string.
EnsurePrefix
type EnsurePrefix<T extends string, P extends string>Adds a prefix to a string, but only if the string does not already start with the prefix.
UnPrefix
type UnPrefix<T extends string, P extends string>Removes a prefix from a string (if it exists).
Suffix
type Suffix<T extends string, S extends string>Adds a suffix to a string.
EnsureSuffix
type EnsureSuffix<
T extends string,
S extends string,
>Adds a suffix to a string, but only if the string does not already end with the suffix.
UnSuffix
type UnSuffix<T extends string, S extends string>Removes a suffix from a string (if it exists).
split
Split
type Split<T extends string, S extends string>Join
type Join<T extends ROList<string>, S extends string = "">utils
Stringable
type StringableA type that represents values that can be converted to strings.
Suggest
type Suggest<T>Generates a type that suggests a pre-defined list of choices while accepting any other string.
type Fruit = Suggest<"Apple" | "Orange">;
const f1: Fruit = "Apple"; // Valid + Auto-completion
const f2: Fruit = "Banana"; // ValidStringify
type Stringify<T>Converts a Stringable to its string representation.
type R1 = Stringify<123>; // "123"
type R2 = Stringify<{ a: 1 }>; // neverConcat
type Concat<A extends string, B extends string, S extends string = "">Concatenates two strings with an optional separator.