Skip to content

S (String)

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(search: string): (s: string) => boolean
endsWith(search: string): (s: string) => boolean
includes(search: string): (s: string) => boolean
split(sep: string): (s: string) => string[]
repeat(n: number): (s: string) => string
slice(start: number, end?: number): (s: string) => string
replaceAll(search: string, 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 = pipe(description, S.slice(0, 100))