Well-typed functions for strings
yarn add @typed/strings
# or
npm install --save @typed/strings
All functions are curried!
Curried function to call String.prototype.split
See the code
export const split: Split = curry2(__split)
export type Split = {
(separator: string | RegExp, str: string): Array<string>
(separator: string | RegExp): (str: string) => Array<string>
}
function __split(separator: string | RegExp, str: string): Array<string> {
return str.split(separator)
}
A curried function to call String.prototype.substr
See the code
export const substr: Substr = curry3(__substr)
export type Substr = {
(from: number, length: number | undefined, str: string): string
(from: number, length: number | undefined): (str: string) => string
(from: number): {
(length: number | undefined, str: string): string
(length: number | undefined): (str: string) => string
}
}
function __substr(from: number, length: number | undefined, str: string): string {
return str.substr(from, length)
}
A curried function to call String.prototype.substring
See the code
export const substring: Substring = curry3(__substring)
export type Substring = {
(from: number, to: number | undefined, str: string): string
(from: number, to: number | undefined): (str: string) => string
(from: number): {
(to: number | undefined, str: string): string
(to: number | undefined): (str: string) => string
}
}
function __substring(from: number, to: number | undefined, str: string): string {
return str.substring(from, to)
}
A function to call String.prototype.toLowerCase
See the code
export const toLowerCase = (str: string) => str.toLowerCase()
A function to call String.prototype.toUpperCase
See the code
export const toUpperCase = (str: string) => str.toUpperCase()
A function to call String.prototype.trim
See the code
export const trim = (str: string): string => str.trim()