Skip to content

Latest commit

 

History

History
180 lines (105 loc) · 2.73 KB

README.md

File metadata and controls

180 lines (105 loc) · 2.73 KB

@typed/strings -- 4.0.0

Well-typed functions for strings

Get it

yarn add @typed/strings
# or
npm install --save @typed/strings

API Documentation

All functions are curried!

split(search: string | RegExp, str: string): Array<string>

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)
}

substr(from: number, length: number | undefined, str: string): string

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)
}

substring(from: number, to: number | undefined, str: string)

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)
}

toLowerCase(str: string): string

A function to call String.prototype.toLowerCase

See the code
export const toLowerCase = (str: string) => str.toLowerCase()

toUpperCase(str: string): string

A function to call String.prototype.toUpperCase

See the code
export const toUpperCase = (str: string) => str.toUpperCase()

trim(str: string): string

A function to call String.prototype.trim

See the code
export const trim = (str: string): string => str.trim()