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
| Parameter | Type | Description |
|---|---|---|
arg | (value: string) => unknown |
Example
breakStr((c) => c === ' ', 'foo bar') //=> ['foo', ' bar']camelize ƒ
Converts a dash-separated string to camelCase.
function camelize(value: string): stringParameters
| Parameter | Type | Description |
|---|---|---|
value | string |
Example
camelize('foo-bar') //=> 'fooBar'capitalize ƒ
Upper-cases the first character of a string.
function capitalize(value: string): stringParameters
| Parameter | Type | Description |
|---|---|---|
value | string |
Example
capitalize('foo') //=> 'Foo'chars ƒ
Splits a string into an array of its characters.
function chars(value: string): string[]Parameters
| Parameter | Type | Description |
|---|---|---|
value | string |
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): booleanParameters
| Parameter | Type | Description |
|---|---|---|
arg | string |
Example
contains('oo', 'foo') //=> truedasherize ƒ
Inserts a dash before each upper-case letter and lower-cases it.
function dasherize(value: string): stringParameters
| Parameter | Type | Description |
|---|---|---|
value | string |
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): stringParameters
| Parameter | Type | Description |
|---|---|---|
arg | number |
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): stringParameters
| Parameter | Type | Description |
|---|---|---|
arg | (value: string) => unknown |
Example
dropWhile((c) => c === ' ', ' hi') //=> 'hi'empty ƒ
Returns whether a string has no characters.
function empty(value: string): booleanParameters
| Parameter | Type | Description |
|---|---|---|
value | string |
Example
empty('') //=> truejoin ƒ
Joins an array of strings with a separator; curried.
function join(sep: string): (values: readonly string[]) => string
function join(sep: string, values: readonly string[]): stringParameters
| Parameter | Type | Description |
|---|---|---|
sep | string |
Example
join('-', ['a', 'b']) //=> 'a-b'lines ƒ
Splits a string into lines on CR/LF boundaries.
function lines(value: string): string[]Parameters
| Parameter | Type | Description |
|---|---|---|
value | string |
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): stringParameters
| Parameter | Type | Description |
|---|---|---|
arg | string |
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): stringParameters
| Parameter | Type | Description |
|---|---|---|
arg | number |
Example
repeat(3, 'ab') //=> 'ababab'reverse ƒ
Reverses the characters of a string.
function reverse(value: string): stringParameters
| Parameter | Type | Description |
|---|---|---|
value | string |
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): stringParameters
| Parameter | Type | Description |
|---|---|---|
arg | number |
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
| Parameter | Type | Description |
|---|---|---|
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
| Parameter | Type | Description |
|---|---|---|
sep | string | 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
| Parameter | Type | Description |
|---|---|---|
arg | number |
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): booleanParameters
| Parameter | Type | Description |
|---|---|---|
arg | string |
Example
startsWith('fo', 'foo') //=> truetake ƒ
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): stringParameters
| Parameter | Type | Description |
|---|---|---|
arg | number |
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): stringParameters
| Parameter | Type | Description |
|---|---|---|
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[]): stringParameters
| Parameter | Type | Description |
|---|---|---|
value | readonly string[] |
Example
unchars(['a', 'b', 'c']) //=> 'abc'unlines ƒ
Joins an array of lines with newlines.
function unlines(value: readonly string[]): stringParameters
| Parameter | Type | Description |
|---|---|---|
value | readonly string[] |
Example
unlines(['a', 'b']) //=> 'a\nb'unwords ƒ
Joins an array of words with spaces.
function unwords(value: readonly string[]): stringParameters
| Parameter | Type | Description |
|---|---|---|
value | readonly string[] |
Example
unwords(['foo', 'bar']) //=> 'foo bar'words ƒ
Splits a string into words on whitespace.
function words(value: string): string[]Parameters
| Parameter | Type | Description |
|---|---|---|
value | string |
Example
words('foo bar') //=> ['foo', 'bar']