String
JavaScript String API
t
Deprecated
type t = stringmake
Deprecated
let make: 'a => tmake(value) converts the given value to a string.
Examples
RESCRIPTJs.String2.make(3.5) == "3.5"
Js.String2.make([1, 2, 3]) == "1,2,3"
fromCharCode
Deprecated
let fromCharCode: int => tfromCharCode(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.
Examples
RESCRIPTJs.String2.fromCharCode(65) == "A"
Js.String2.fromCharCode(0x3c8) == `ψ`
Js.String2.fromCharCode(0xd55c) == `한`
Js.String2.fromCharCode(-64568) == `ψ`
fromCharCodeMany
Deprecated
let fromCharCodeMany: array<int> => tfromCharCodeMany([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.
fromCodePoint
Deprecated
let fromCodePoint: int => tfromCodePoint(n) creates a string containing the character corresponding to
that numeric code point. If the number is not a valid code point, it throws
RangeError.Thus, fromCodePoint(0x1F63A) will produce a correct value,
unlike fromCharCode(0x1F63A), and fromCodePoint(-5) will throw a
RangeError.
See String.fromCodePoint
on MDN.
Examples
RESCRIPTJs.String2.fromCodePoint(65) == "A"
Js.String2.fromCodePoint(0x3c8) == `ψ`
Js.String2.fromCodePoint(0xd55c) == `한`
Js.String2.fromCodePoint(0x1f63a) == `😺`
fromCodePointMany
Deprecated
let fromCodePointMany: array<int> => tfromCodePointMany([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.
Examples
RESCRIPTJs.String2.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺`
length
Deprecated
let length: t => intlength(s) returns the length of the given string. See
String.length
on MDN.
Examples
RESCRIPTJs.String2.length("abcd") == 4
get
Deprecated
let get: (t, int) => tget(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>.
Examples
RESCRIPTJs.String2.get("Reason", 0) == "R"
Js.String2.get("Reason", 4) == "o"
Js.String2.get(`Rẽasöń`, 5) == `ń`
charAt
let charAt: (int, t) => tcharCodeAt
let charCodeAt: (int, t) => floatcodePointAt
let codePointAt: (int, t) => option<int>concat
let concat: (t, t) => tconcatMany
let concatMany: (array<t>, t) => tendsWith
let endsWith: (t, t) => boolendsWithFrom
let endsWithFrom: (t, int, t) => boolincludes
let includes: (t, t) => boolincludesFrom
let includesFrom: (t, int, t) => boolindexOf
let indexOf: (t, t) => intindexOfFrom
let indexOfFrom: (t, int, t) => intlastIndexOf
let lastIndexOf: (t, t) => intlastIndexOfFrom
let lastIndexOfFrom: (t, int, t) => intlocaleCompare
let localeCompare: (t, t) => floatmatch_
let match_: (Js_re.t, t) => option<array<option<t>>>normalize
Deprecated
let normalize: t => tnormalize(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.
normalizeByForm
let normalizeByForm: (t, t) => trepeat
let repeat: (int, t) => treplace
let replace: (t, t, t) => treplaceByRe
let replaceByRe: (Js_re.t, t, t) => tunsafeReplaceBy0
let unsafeReplaceBy0: (Js_re.t, (t, int, t) => t, t) => tunsafeReplaceBy1
let unsafeReplaceBy1: (Js_re.t, (t, t, int, t) => t, t) => tunsafeReplaceBy2
let unsafeReplaceBy2: (Js_re.t, (t, t, t, int, t) => t, t) => tunsafeReplaceBy3
let unsafeReplaceBy3: (Js_re.t, (t, t, t, t, int, t) => t, t) => tsearch
let search: (Js_re.t, t) => intslice
let slice: (~from: int, ~to_: int, t) => tsliceToEnd
let sliceToEnd: (~from: int, t) => tsplit
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) => boolstartsWithFrom
let startsWithFrom: (t, int, t) => boolsubstr
let substr: (~from: int, t) => tsubstrAtMost
let substrAtMost: (~from: int, ~length: int, t) => tsubstring
let substring: (~from: int, ~to_: int, t) => tsubstringToEnd
let substringToEnd: (~from: int, t) => ttoLowerCase
Deprecated
let toLowerCase: t => ttoLowerCase(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.
Examples
RESCRIPTJs.String.toLowerCase("ABC") == "abc"
Js.String.toLowerCase(`ΣΠ`) == `σπ`
Js.String.toLowerCase(`ΠΣ`) == `πς`
toLocaleLowerCase
Deprecated
let toLocaleLowerCase: t => ttoLocaleLowerCase(str) converts str to lower case using the current locale.
See String.toLocaleLowerCase
on MDN.
toUpperCase
Deprecated
let toUpperCase: t => ttoUpperCase(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.
Examples
RESCRIPTJs.String.toUpperCase("abc") == "ABC"
Js.String.toUpperCase(`Straße`) == `STRASSE`
Js.String.toUpperCase(`πς`) == `ΠΣ`
toLocaleUpperCase
Deprecated
let toLocaleUpperCase: t => ttoLocaleUpperCase(str) converts str to upper case using the current locale.
See String.to:LocaleUpperCase
on MDN.
trim
Deprecated
let trim: t => ttrim(str) returns a string that is str with whitespace stripped from both
ends. Internal whitespace is not removed.
See String.trim
on MDN.
Examples
RESCRIPTJs.String.trim(" abc def ") == "abc def"
Js.String.trim("\n\r\t abc def \n\n\t\r ") == "abc def"
anchor
let anchor: (t, t) => tlink
let link: (t, t) => tcastToArrayLike
Deprecated
This has been deprecated and will be removed in v13. Use functions from the String module instead.
let castToArrayLike: t => Js_array2.array_like<t>