API / Js / Js_string

Js_string

JavaScript String API

t

type t = string

make

make(value) converts the given value to a string.

RES
Js.String2.make(3.5) == "3.5" Js.String2.make([1, 2, 3]) == "1,2,3"
let make: 'a => t

fromCharCode

fromCharCode(n) creates a string containing the character corresponding to that number; n ranges from 0 to 65535. If out of range, the lower 16 bits of the value are used. Thus, fromCharCode(0x1F63A) gives the same result as fromCharCode(0xF63A). See String.fromCharCode on MDN.

RES
Js.String2.fromCharCode(65) == "A" Js.String2.fromCharCode(0x3c8) == `ψ` Js.String2.fromCharCode(0xd55c) == `한` Js.String2.fromCharCode(-64568) == `ψ`
let fromCharCode: int => t

fromCharCodeMany

fromCharCodeMany([n1, n2, n3]) creates a string from the characters corresponding to the given numbers, using the same rules as fromCharCode. See String.fromCharCode on MDN.

let fromCharCodeMany: array<int> => t

fromCodePoint

fromCodePoint(n) creates a string containing the character corresponding to that numeric code point. If the number is not a valid code point, it raises RangeError.Thus, fromCodePoint(0x1F63A) will produce a correct value, unlike fromCharCode(0x1F63A), and fromCodePoint(-5) will raise a RangeError.

See String.fromCodePoint on MDN.

RES
Js.String2.fromCodePoint(65) == "A" Js.String2.fromCodePoint(0x3c8) == `ψ` Js.String2.fromCodePoint(0xd55c) == `한` Js.String2.fromCodePoint(0x1f63a) == `😺`
let fromCodePoint: int => t

fromCodePointMany

fromCodePointMany([n1, n2, n3]) creates a string from the characters corresponding to the given code point numbers, using the same rules as fromCodePoint.

See String.fromCodePoint on MDN.

RES
Js.String2.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺`
let fromCodePointMany: array<int> => t

length

length(s) returns the length of the given string. See String.length on MDN.

RES
Js.String2.length("abcd") == 4
let length: t => int

get

get(s, n) returns as a string the character at the given index number. If n is out of range, this function returns undefined, so at some point this function may be modified to return option(string).

RES
Js.String2.get("Reason", 0) == "R" Js.String2.get("Reason", 4) == "o" Js.String2.get(`Rẽasöń`, 5) == `ń`
let get: (t, int) => t

charAt

let charAt: (int, t) => t

charCodeAt

let charCodeAt: (int, t) => float

codePointAt

let codePointAt: (int, t) => option<int>

concat

let concat: (t, t) => t

concatMany

let concatMany: (array<t>, t) => t

endsWith

let endsWith: (t, t) => bool

endsWithFrom

let endsWithFrom: (t, int, t) => bool

includes

let includes: (t, t) => bool

includesFrom

let includesFrom: (t, int, t) => bool

indexOf

let indexOf: (t, t) => int

indexOfFrom

let indexOfFrom: (t, int, t) => int

lastIndexOf

let lastIndexOf: (t, t) => int

lastIndexOfFrom

let lastIndexOfFrom: (t, int, t) => int

localeCompare

let localeCompare: (t, t) => float

match_

let match_: (Js_re.t, t) => option<array<option<t>>>

normalize

normalize(str) returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition. Consider the character ã, which can be represented as the single codepoint \u00e3 or the combination of a lower case letter A \u0061 and a combining tilde \u0303. Normalization ensures that both can be stored in an equivalent binary representation.

See String.normalize on MDN.

See also Unicode technical report #15 for details.

let normalize: t => t

normalizeByForm

let normalizeByForm: (t, t) => t

repeat

let repeat: (int, t) => t

replace

let replace: (t, t, t) => t

replaceByRe

let replaceByRe: (Js_re.t, t, t) => t

unsafeReplaceBy0

let unsafeReplaceBy0: (Js_re.t, (t, int, t) => t, t) => t

unsafeReplaceBy1

let unsafeReplaceBy1: (Js_re.t, (t, t, int, t) => t, t) => t

unsafeReplaceBy2

let unsafeReplaceBy2: (Js_re.t, (t, t, t, int, t) => t, t) => t

unsafeReplaceBy3

let unsafeReplaceBy3: (Js_re.t, (t, t, t, t, int, t) => t, t) => t

search

let search: (Js_re.t, t) => int

slice

let slice: (~from: int, ~to_: int, t) => t

sliceToEnd

let sliceToEnd: (~from: int, t) => t

split

let split: (t, t) => array<t>

splitAtMost

let splitAtMost: (t, ~limit: int, t) => array<t>

splitByRe

let splitByRe: (Js_re.t, t) => array<option<t>>

splitByReAtMost

let splitByReAtMost: (Js_re.t, ~limit: int, t) => array<option<t>>

startsWith

let startsWith: (t, t) => bool

startsWithFrom

let startsWithFrom: (t, int, t) => bool

substr

let substr: (~from: int, t) => t

substrAtMost

let substrAtMost: (~from: int, ~length: int, t) => t

substring

let substring: (~from: int, ~to_: int, t) => t

substringToEnd

let substringToEnd: (~from: int, t) => t

toLowerCase

toLowerCase(str) converts str to lower case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can give different results depending upon context, for example with the Greek letter sigma, which has two different lower case forms; one when it is the last character in a string and another when it is not.

See String.toLowerCase on MDN.

RES
Js.String.toLowerCase("ABC") == "abc" Js.String.toLowerCase(`ΣΠ`) == `σπ` Js.String.toLowerCase(`ΠΣ`) == `πς`
let toLowerCase: t => t

toLocaleLowerCase

toLocaleLowerCase(str) converts str to lower case using the current locale.

See String.toLocaleLowerCase on MDN.

let toLocaleLowerCase: t => t

toUpperCase

toUpperCase(str) converts str to upper case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can expand the number of letters in the result; for example the German ß capitalizes to two Ses in a row.

See String.toUpperCase on MDN.

RES
Js.String.toUpperCase("abc") == "ABC" Js.String.toUpperCase(`Straße`) == `STRASSE` Js.String.toUpperCase(`πς`) == `ΠΣ`
let toUpperCase: t => t

toLocaleUpperCase

toLocaleUpperCase(str) converts str to upper case using the current locale.

See String.to:LocaleUpperCase on MDN.

let toLocaleUpperCase: t => t

trim

trim(str) returns a string that is str with whitespace stripped from both ends. Internal whitespace is not removed.

See String.trim on MDN.

RES
Js.String.trim(" abc def ") == "abc def" Js.String.trim("\n\r\t abc def \n\n\t\r ") == "abc def"
let trim: t => t

anchor

let anchor: (t, t) => t

link

let link: (t, t) => t

castToArrayLike

Casts its argument to an array_like entity that can be processed by functions such as Js.Array2.fromMap()

RES
let s = "abcde" let arr = Js.Array2.fromMap(Js.String.castToArrayLike(s), x => x) arr == ["a", "b", "c", "d", "e"]
let castToArrayLike: t => Js_array2.array_like<t>