String
JavaScript String API
t
Deprecated
type t = string
make
Deprecated
let make: 'a => t
make(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 => t
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.
Examples
RESCRIPTJs.String2.fromCharCode(65) == "A"
Js.String2.fromCharCode(0x3c8) == `ψ`
Js.String2.fromCharCode(0xd55c) == `한`
Js.String2.fromCharCode(-64568) == `ψ`
fromCharCodeMany
Deprecated
let fromCharCodeMany: array<int> => t
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.
fromCodePoint
Deprecated
let fromCodePoint: int => t
fromCodePoint(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> => t
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.
Examples
RESCRIPTJs.String2.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺`
length
Deprecated
let length: t => int
length(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) => t
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>
.
Examples
RESCRIPTJs.String2.get("Reason", 0) == "R"
Js.String2.get("Reason", 4) == "o"
Js.String2.get(`Rẽasöń`, 5) == `ń`
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
Deprecated
let normalize: t => t
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.
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
Deprecated
let toLowerCase: t => t
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.
Examples
RESCRIPTJs.String.toLowerCase("ABC") == "abc"
Js.String.toLowerCase(`ΣΠ`) == `σπ`
Js.String.toLowerCase(`ΠΣ`) == `πς`
toLocaleLowerCase
Deprecated
let toLocaleLowerCase: t => t
toLocaleLowerCase(str)
converts str
to lower case using the current locale.
See String.toLocaleLowerCase
on MDN.
toUpperCase
Deprecated
let toUpperCase: t => t
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.
Examples
RESCRIPTJs.String.toUpperCase("abc") == "ABC"
Js.String.toUpperCase(`Straße`) == `STRASSE`
Js.String.toUpperCase(`πς`) == `ΠΣ`
toLocaleUpperCase
Deprecated
let toLocaleUpperCase: t => t
toLocaleUpperCase(str)
converts str
to upper case using the current locale.
See String.to:LocaleUpperCase
on MDN.
trim
Deprecated
let trim: t => t
trim(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) => t
link
let link: (t, t) => t
castToArrayLike
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>