UNPKG

@mobily/ts-belt

Version:

🔧 Fast, modern, and practical utility library for FP in TypeScript.

251 lines (214 loc) • 7.72 kB
// @flow import type { Option } from "../Option"; import type { Array } from "../types"; /** * Converts the given value to a string. */ declare export function make<A>(value: A): string; /** * Returns the length of the given string. */ declare export function length(str: string): number; /** * Returns a new string with `appendValue` added after `str`. */ declare export function concat(appendValue: string): (str: string) => string; declare export function concat(str: string, appendValue: string): string; /** * Alias for `concat`. */ declare export function append(appendValue: string): (str: string) => string; declare export function append(str: string, appendValue: string): string; /** * Returns a new string with `prependValue` added before `str`. */ declare export function prepend(prependValue: string): (str: string) => string; declare export function prepend(str: string, prependValue: string): string; /** * Returns the substring of `str` starting at character `start` up to but not including `end`. */ declare export function slice(str: string, start: number, end: number): string; declare export function slice( start: number, end: number ): (str: string) => string; /** * Returns the substring of `str` starting at character `start` to the end of the string. */ declare export function sliceToEnd(str: string, start: number): string; declare export function sliceToEnd(start: number): (str: string) => string; /** * Converts `str` to lower case. */ declare export function toLowerCase(str: string): string; /** * Converts `str` to upper case. */ declare export function toUpperCase(str: string): string; /** * Returns a new string with leading and trailing whitespace removed from `str`. */ declare export function trim(str: string): string; /** * Returns a new string with leading whitespace removed from `str`. */ declare export function trimStart(str: string): string; /** * Returns a new string with trailing whitespace removed from `str`. */ declare export function trimEnd(str: string): string; /** * Returns `true` if the provided string is empty. */ declare export function isEmpty(str: string): boolean; /** * Returns `true` if the provided string is not empty. */ declare export function isNotEmpty(str: string): boolean; /** * Splits the given string at every occurrence of `delimiter` and returns an array of the resulting substrings. */ declare export function split( delimiter: string ): (str: string) => Array<string>; declare export function split(str: string, delimiter: string): Array<string>; /** * Splits the given string at every occurrence of `regex` and returns an array of the resulting substrings. */ declare export function splitByRe( str: string, regex: RegExp ): Array<Option<string>>; declare export function splitByRe( regex: RegExp ): (str: string) => Array<Option<string>>; /** * Splits the string at the given index, returning a tuple of the parts. */ declare export function splitAt(str: string, index: number): [string, string]; declare export function splitAt( index: number ): (str: string) => [string, string]; /** * Returns `true` if `searchValue` appears anywhere in the given string. */ declare export function includes(searchValue: string): (str: string) => boolean; declare export function includes(str: string, searchValue: string): boolean; /** * Replaces the first occurrence of `oldValue` with `newValue` in the given string and returns a new string. */ declare export function replace( oldValue: string, newValue: string ): (str: string) => string; declare export function replace( str: string, oldValue: string, newValue: string ): string; /** * Replaces each occurrence of `oldValue` with `newValue` in the given string and returns a new string. */ declare export function replaceAll( oldValue: string, newValue: string ): (str: string) => string; declare export function replaceAll( str: string, oldValue: string, newValue: string ): string; /** * Replaces the matched regular expression with `newValue` in the given string and returns a new string. */ declare export function replaceByRe( str: string, regex: RegExp, value: string ): string; declare export function replaceByRe( regex: RegExp, value: string ): (str: string) => string; /** * Returns a new string with the first occurrence of `value` removed from `str`. */ declare export function remove(value: string): (str: string) => string; declare export function remove(str: string, value: string): string; /** * Returns a new string with every occurrence of `value` removed from `str`. */ declare export function removeAll(value: string): (str: string) => string; declare export function removeAll(str: string, value: string): string; /** * Returns `Some(index)`, where `index` is the starting position of the first match of regular expression in the given string. */ declare export function search(str: string, regex: RegExp): Option<number>; declare export function search(regex: RegExp): (str: string) => Option<number>; /** * Matches the given string against the provided regular expression, ir returns `None` if there is no match. */ declare export function match( str: string, regex: RegExp ): Option<Array<string>>; declare export function match( regex: RegExp ): (str: string) => Option<Array<string>>; /** * Returns a string consisting of `n` repetitions of `str`. */ declare export function repeat(str: string, n: number): string; declare export function repeat(n: number): (str: string) => string; /** * Returns `Some(index)`, where `index` is the starting position of the first occurrence of `searchValue` within `str`. */ declare export function indexOf( searchValue: string ): (str: string) => Option<number>; declare export function indexOf( str: string, searchValue: string ): Option<number>; /** * Returns `Some(index)`, where `index` is the starting position of the last occurrence of `searchValue` within `str`. */ declare export function lastIndexOf( searchValue: string ): (str: string) => Option<number>; declare export function lastIndexOf( str: string, searchValue: string ): Option<number>; /** * Returns `true` if the given string ends with `substr`. */ declare export function endsWith(substr: string): (str: string) => boolean; declare export function endsWith(str: string, substr: string): boolean; /** * Returns `true` if the given string starts with `substr`. */ declare export function startsWith(substr: string): (str: string) => boolean; declare export function startsWith(str: string, substr: string): boolean; /** * Returns `value`, where `value` is a string consisting of the character at location `n` in the string, or `undefined` if the `n` is out of range. */ declare export function getUnsafe(str: string, n: number): string; declare export function getUnsafe(n: number): (str: string) => string; /** * Returns `Some(value)`, where `value` is a string consisting of the character at location `n` in the string, or `None` if the `n` is out of range. */ declare export function get(str: string, n: number): Option<string>; declare export function get(n: number): (str: string) => Option<string>; /** * Creates an array with one character of `str` per element. */ declare export function toArray(str: string): Array<string>; /** * Returns `Some(value)` where `value` is the first character of the string, or `None` if the given string is empty. */ declare export function head(str: string): Option<string>; /** * Returns `Some(value)` where `value` is the last character of the string, or `None` if the given string is empty. */ declare export function last(str: string): Option<string>;