S (String)
The 19 dual String operations appear with both shapes in the complete dual-call catalogue.
Single-argument
Section titled “Single-argument”trim(s: string): stringtrimStart(s: string): stringtrimEnd(s: string): stringtoLowerCase(s: string): stringtoUpperCase(s: string): stringisEmpty(s: string): booleanlength(s: string): numberDual-form
Section titled “Dual-form”startsWith(s: string, search: string): booleanstartsWith(search: string): (s: string) => booleanendsWith(s: string, search: string): booleanendsWith(search: string): (s: string) => booleanincludes(s: string, search: string): booleanincludes(search: string): (s: string) => booleansplit(s: string, sep: string | RegExp): string[]split(sep: string | RegExp): (s: string) => string[]repeat(s: string, n: number): stringrepeat(n: number): (s: string) => stringslice(s: string, start: number, end?: number): stringslice(start: number, end?: number): (s: string) => stringreplaceAll(s: string, search: string | RegExp, replacement: string): stringreplaceAll(search: string | RegExp, replacement: string): (s: string) => stringExamples
Section titled “Examples”import { pipe } from '@stopcock/fp'import * as S from '@stopcock/fp/string'
// slug from titlepipe(' Hello World! ', S.trim, S.toLowerCase, S.replaceAll(' ', '-'), S.replaceAll('!', ''))// 'hello-world'
// parse CSV headerpipe('name,email,role', S.split(','))// ['name', 'email', 'role']
// check file extensionpipe('report.pdf', S.endsWith('.pdf')) // true
// templatepipe('Hello, NAME!', S.replaceAll('NAME', user.name))
// truncateconst preview = S.slice(description, 0, 100) // direct, data-firstconst alsoPreview = pipe(description, S.slice(0, 100)) // curried, data-last