prelude-js logoprelude-js

preludejs/Str API

Complete API reference for preludejs/Str

preludejs/Str API Reference

Core

breakStr ƒ

Splits a string at the first character matching the predicate; curried.

function breakStr(arg: (value: string) => unknown): ((arg: string) => [string, string]) & ((arg: string) => [string, string])
function breakStr(arg: (value: string) => unknown, rest_0: string): [string, string]

Parameters

ParameterTypeDescription
arg(value: string) => unknown

Example

breakStr((c) => c === ' ', 'foo bar') //=> ['foo', ' bar']

camelize ƒ

Converts a dash-separated string to camelCase.

function camelize(value: string): string

Parameters

ParameterTypeDescription
valuestring

Example

camelize('foo-bar') //=> 'fooBar'

capitalize ƒ

Upper-cases the first character of a string.

function capitalize(value: string): string

Parameters

ParameterTypeDescription
valuestring

Example

capitalize('foo') //=> 'Foo'

chars ƒ

Splits a string into an array of its characters.

function chars(value: string): string[]

Parameters

ParameterTypeDescription
valuestring

Example

chars('abc') //=> ['a', 'b', 'c']

contains ƒ

Returns whether the target string contains the search string.

function contains(arg: string): ((arg: string) => boolean) & ((arg: string) => boolean)
function contains(arg: string, rest_0: string): boolean

Parameters

ParameterTypeDescription
argstring

Example

contains('oo', 'foo') //=> true

dasherize ƒ

Inserts a dash before each upper-case letter and lower-cases it.

function dasherize(value: string): string

Parameters

ParameterTypeDescription
valuestring

Example

dasherize('fooBar') //=> 'foo-bar'

drop ƒ

Drops the first count characters of a string; curried.

function drop(arg: number): ((arg: string) => string) & ((arg: string) => string)
function drop(arg: number, rest_0: string): string

Parameters

ParameterTypeDescription
argnumber

Example

drop(2, 'hello') //=> 'llo'

dropWhile ƒ

Drops leading characters while the predicate holds; curried.

function dropWhile(arg: (value: string) => unknown): ((arg: string) => string) & ((arg: string) => string)
function dropWhile(arg: (value: string) => unknown, rest_0: string): string

Parameters

ParameterTypeDescription
arg(value: string) => unknown

Example

dropWhile((c) => c === ' ', '  hi') //=> 'hi'

empty ƒ

Returns whether a string has no characters.

function empty(value: string): boolean

Parameters

ParameterTypeDescription
valuestring

Example

empty('') //=> true

join ƒ

Joins an array of strings with a separator; curried.

function join(sep: string): (values: readonly string[]) => string
function join(sep: string, values: readonly string[]): string

Parameters

ParameterTypeDescription
sepstring

Example

join('-', ['a', 'b']) //=> 'a-b'

lines ƒ

Splits a string into lines on CR/LF boundaries.

function lines(value: string): string[]

Parameters

ParameterTypeDescription
valuestring

Example

lines('a\nb') //=> ['a', 'b']

padLeft ƒ

Left-pads a value using the supplied padding string; curried.

function padLeft(arg: string): ((arg: string | number | null | undefined) => string) & ((arg: string | number | null | undefined) => string)
function padLeft(arg: string, rest_0: string | number | null | undefined): string

Parameters

ParameterTypeDescription
argstring

Example

padLeft('   ', '42') //=> ' 42'

repeat ƒ

Repeats a string count times; curried.

function repeat(arg: number): ((arg: string) => string) & ((arg: string) => string)
function repeat(arg: number, rest_0: string): string

Parameters

ParameterTypeDescription
argnumber

Example

repeat(3, 'ab') //=> 'ababab'

reverse ƒ

Reverses the characters of a string.

function reverse(value: string): string

Parameters

ParameterTypeDescription
valuestring

Example

reverse('abc') //=> 'cba'

slice ƒ

Slices a string between two indices; curried.

function slice(arg: number): ((arg: number) => ((arg: string) => string) & ((arg: string) => string)) & ((arg: number, rest_0: string) => string)
function slice(arg: number, rest_0: number, rest_1: string): string

Parameters

ParameterTypeDescription
argnumber

Example

slice(1, 3, 'hello') //=> 'el'

span ƒ

Splits a string into the longest prefix matching the predicate and the rest; curried.

function span(arg: (value: string) => unknown): ((arg: string) => [string, string]) & ((arg: string) => [string, string])
function span(arg: (value: string) => unknown, rest_0: string): [string, string]

Parameters

ParameterTypeDescription
arg(value: string) => unknown

Example

span((c) => c !== ' ', 'foo bar') //=> ['foo', ' bar']

split ƒ

Splits a string on a separator; curried.

function split(sep: string | RegExp): (value: string) => string[]
function split(sep: string | RegExp, value: string): string[]

Parameters

ParameterTypeDescription
sepstring | RegExp

Example

split(',', 'a,b,c') //=> ['a', 'b', 'c']

splitAt ƒ

Splits a string into two parts at the given index; curried.

function splitAt(arg: number): ((arg: string) => [string, string]) & ((arg: string) => [string, string])
function splitAt(arg: number, rest_0: string): [string, string]

Parameters

ParameterTypeDescription
argnumber

Example

splitAt(2, 'hello') //=> ['he', 'llo']

startsWith ƒ

Returns whether the target string starts with the search string.

function startsWith(arg: string): ((arg: string) => boolean) & ((arg: string) => boolean)
function startsWith(arg: string, rest_0: string): boolean

Parameters

ParameterTypeDescription
argstring

Example

startsWith('fo', 'foo') //=> true

take ƒ

Takes the first count characters of a string; curried.

function take(arg: number): ((arg: string) => string) & ((arg: string) => string)
function take(arg: number, rest_0: string): string

Parameters

ParameterTypeDescription
argnumber

Example

take(2, 'hello') //=> 'he'

takeWhile ƒ

Takes leading characters while the predicate holds; curried.

function takeWhile(arg: (value: string) => unknown): ((arg: string) => string) & ((arg: string) => string)
function takeWhile(arg: (value: string) => unknown, rest_0: string): string

Parameters

ParameterTypeDescription
arg(value: string) => unknown

Example

takeWhile((c) => c !== ' ', 'foo bar') //=> 'foo'

unchars ƒ

Joins an array of characters into a string.

function unchars(value: readonly string[]): string

Parameters

ParameterTypeDescription
valuereadonly string[]

Example

unchars(['a', 'b', 'c']) //=> 'abc'

unlines ƒ

Joins an array of lines with newlines.

function unlines(value: readonly string[]): string

Parameters

ParameterTypeDescription
valuereadonly string[]

Example

unlines(['a', 'b']) //=> 'a\nb'

unwords ƒ

Joins an array of words with spaces.

function unwords(value: readonly string[]): string

Parameters

ParameterTypeDescription
valuereadonly string[]

Example

unwords(['foo', 'bar']) //=> 'foo bar'

words ƒ

Splits a string into words on whitespace.

function words(value: string): string[]

Parameters

ParameterTypeDescription
valuestring

Example

words('foo  bar') //=> ['foo', 'bar']

On this page