Skip to content

S (String)

The 19 dual String operations appear with both shapes in the complete dual-call catalogue.

trim(s: string): string
trimStart(s: string): string
trimEnd(s: string): string
toLowerCase(s: string): string
toUpperCase(s: string): string
isEmpty(s: string): boolean
length(s: string): number
startsWith(s: string, search: string): boolean
startsWith(search: string): (s: string) => boolean
endsWith(s: string, search: string): boolean
endsWith(search: string): (s: string) => boolean
includes(s: string, search: string): boolean
includes(search: string): (s: string) => boolean
split(s: string, sep: string | RegExp): string[]
split(sep: string | RegExp): (s: string) => string[]
repeat(s: string, n: number): string
repeat(n: number): (s: string) => string
slice(s: string, start: number, end?: number): string
slice(start: number, end?: number): (s: string) => string
replaceAll(s: string, search: string | RegExp, replacement: string): string
replaceAll(search: string | RegExp, replacement: string): (s: string) => string
import { pipe } from '@stopcock/fp'
import * as S from '@stopcock/fp/string'
// slug from title
pipe(' Hello World! ', S.trim, S.toLowerCase, S.replaceAll(' ', '-'), S.replaceAll('!', ''))
// 'hello-world'
// parse CSV header
pipe('name,email,role', S.split(','))
// ['name', 'email', 'role']
// check file extension
pipe('report.pdf', S.endsWith('.pdf')) // true
// template
pipe('Hello, NAME!', S.replaceAll('NAME', user.name))
// truncate
const preview = S.slice(description, 0, 100) // direct, data-first
const alsoPreview = pipe(description, S.slice(0, 100)) // curried, data-last