This is the latest docs version
Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • X
  • Bluesky
  • GitHub
  • Forum
Js Module
Overview
Js
submodules
  • Array
  • Array2
  • BigInt
  • Blob
  • Console
  • Date
  • Dict
  • Exn
  • File
  • Float
  • Global
  • Int
  • Json
    • Kind
  • List
  • Map
  • Math
  • Null
  • Null_undefined
  • Nullable
  • Obj
  • Option
  • Promise
  • Promise2
  • Re
  • Result
  • Set
  • String
    • t
      t
    • v
      make
    • v
      fromCharCode
    • v
      fromCharCodeMany
    • v
      fromCodePoint
    • v
      fromCodePointMany
    • v
      length
    • v
      get
    • v
      charAt
    • v
      charCodeAt
    • v
      codePointAt
    • v
      concat
    • v
      concatMany
    • v
      endsWith
    • v
      endsWithFrom
    • v
      includes
    • v
      includesFrom
    • v
      indexOf
    • v
      indexOfFrom
    • v
      lastIndexOf
    • v
      lastIndexOfFrom
    • v
      localeCompare
    • v
      match_
    • v
      normalize
    • v
      normalizeByForm
    • v
      repeat
    • v
      replace
    • v
      replaceByRe
    • v
      unsafeReplaceBy0
    • v
      unsafeReplaceBy1
    • v
      unsafeReplaceBy2
    • v
      unsafeReplaceBy3
    • v
      search
    • v
      slice
    • v
      sliceToEnd
    • v
      split
    • v
      splitAtMost
    • v
      splitByRe
    • v
      splitByReAtMost
    • v
      startsWith
    • v
      startsWithFrom
    • v
      substr
    • v
      substrAtMost
    • v
      substring
    • v
      substringToEnd
    • v
      toLowerCase
    • v
      toLocaleLowerCase
    • v
      toUpperCase
    • v
      toLocaleUpperCase
    • v
      trim
    • v
      anchor
    • v
      link
    • v
      castToArrayLike
  • String2
  • TypedArray2
    • DataView
    • Float64Array
    • Float32Array
    • Uint32Array
    • Int32Array
    • Uint16Array
    • Int16Array
    • Uint8ClampedArray
    • Uint8Array
    • Int8Array
    • ArrayBuffer
    Typed_array
    • DataView
    • Float64_array
    • Float64Array
    • Float32_array
    • Float32Array
    • Uint32Array
    • Int32_array
    • Int32Array
    • Uint16Array
    • Int16Array
    • Uint8ClampedArray
    • Uint8Array
    • Int8Array
    • S
    • ArrayBuffer
    • Type
  • Types
  • Undefined
  • Vector
  • WeakMap
  • WeakSet
  • API / Js / String

    String

    JavaScript String API

    t

    RESCRIPT
    type t = string

    make

    RESCRIPT
    let make: 'a => t

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

    Examples

    RESCRIPT
    Js.String2.make(3.5) == "3.5" Js.String2.make([1, 2, 3]) == "1,2,3"

    fromCharCode

    RESCRIPT
    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

    RESCRIPT
    Js.String2.fromCharCode(65) == "A" Js.String2.fromCharCode(0x3c8) == `ψ` Js.String2.fromCharCode(0xd55c) == `한` Js.String2.fromCharCode(-64568) == `ψ`

    fromCharCodeMany

    RESCRIPT
    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

    RESCRIPT
    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 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.

    Examples

    RESCRIPT
    Js.String2.fromCodePoint(65) == "A" Js.String2.fromCodePoint(0x3c8) == `ψ` Js.String2.fromCodePoint(0xd55c) == `한` Js.String2.fromCodePoint(0x1f63a) == `😺`

    fromCodePointMany

    RESCRIPT
    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

    RESCRIPT
    Js.String2.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺`

    length

    RESCRIPT
    let length: t => int

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

    Examples

    RESCRIPT
    Js.String2.length("abcd") == 4

    get

    RESCRIPT
    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

    RESCRIPT
    Js.String2.get("Reason", 0) == "R" Js.String2.get("Reason", 4) == "o" Js.String2.get(`Rẽasöń`, 5) == `ń`

    charAt

    RESCRIPT
    let charAt: (int, t) => t

    charCodeAt

    RESCRIPT
    let charCodeAt: (int, t) => float

    codePointAt

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

    concat

    RESCRIPT
    let concat: (t, t) => t

    concatMany

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

    endsWith

    RESCRIPT
    let endsWith: (t, t) => bool

    endsWithFrom

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

    includes

    RESCRIPT
    let includes: (t, t) => bool

    includesFrom

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

    indexOf

    RESCRIPT
    let indexOf: (t, t) => int

    indexOfFrom

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

    lastIndexOf

    RESCRIPT
    let lastIndexOf: (t, t) => int

    lastIndexOfFrom

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

    localeCompare

    RESCRIPT
    let localeCompare: (t, t) => float

    match_

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

    normalize

    RESCRIPT
    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

    RESCRIPT
    let normalizeByForm: (t, t) => t

    repeat

    RESCRIPT
    let repeat: (int, t) => t

    replace

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

    replaceByRe

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

    unsafeReplaceBy0

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

    unsafeReplaceBy1

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

    unsafeReplaceBy2

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

    unsafeReplaceBy3

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

    search

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

    slice

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

    sliceToEnd

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

    split

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

    splitAtMost

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

    splitByRe

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

    splitByReAtMost

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

    startsWith

    RESCRIPT
    let startsWith: (t, t) => bool

    startsWithFrom

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

    substr

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

    substrAtMost

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

    substring

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

    substringToEnd

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

    toLowerCase

    RESCRIPT
    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

    RESCRIPT
    Js.String.toLowerCase("ABC") == "abc" Js.String.toLowerCase(`ΣΠ`) == `σπ` Js.String.toLowerCase(`ΠΣ`) == `πς`

    toLocaleLowerCase

    RESCRIPT
    let toLocaleLowerCase: t => t

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

    See String.toLocaleLowerCase on MDN.

    toUpperCase

    RESCRIPT
    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

    RESCRIPT
    Js.String.toUpperCase("abc") == "ABC" Js.String.toUpperCase(`Straße`) == `STRASSE` Js.String.toUpperCase(`πς`) == `ΠΣ`

    toLocaleUpperCase

    RESCRIPT
    let toLocaleUpperCase: t => t

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

    See String.to:LocaleUpperCase on MDN.

    trim

    RESCRIPT
    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

    RESCRIPT
    Js.String.trim(" abc def ") == "abc def" Js.String.trim("\n\r\t abc def \n\n\t\r ") == "abc def"

    anchor

    RESCRIPT
    let anchor: (t, t) => t

    link

    RESCRIPT
    let link: (t, t) => t

    castToArrayLike

    RESCRIPT
    let castToArrayLike: t => Js_array2.array_like<t>

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

    Examples

    RESCRIPT
    let s = "abcde" let arr = Js.Array2.fromMap(Js.String.castToArrayLike(s), x => x) arr == ["a", "b", "c", "d", "e"]
    Types and values
    • t
      t
    • v
      make
    • v
      fromCharCode
    • v
      fromCharCodeMany
    • v
      fromCodePoint
    • v
      fromCodePointMany
    • v
      length
    • v
      get
    • v
      charAt
    • v
      charCodeAt
    • v
      codePointAt
    • v
      concat
    • v
      concatMany
    • v
      endsWith
    • v
      endsWithFrom
    • v
      includes
    • v
      includesFrom
    • v
      indexOf
    • v
      indexOfFrom
    • v
      lastIndexOf
    • v
      lastIndexOfFrom
    • v
      localeCompare
    • v
      match_
    • v
      normalize
    • v
      normalizeByForm
    • v
      repeat
    • v
      replace
    • v
      replaceByRe
    • v
      unsafeReplaceBy0
    • v
      unsafeReplaceBy1
    • v
      unsafeReplaceBy2
    • v
      unsafeReplaceBy3
    • v
      search
    • v
      slice
    • v
      sliceToEnd
    • v
      split
    • v
      splitAtMost
    • v
      splitByRe
    • v
      splitByReAtMost
    • v
      startsWith
    • v
      startsWithFrom
    • v
      substr
    • v
      substrAtMost
    • v
      substring
    • v
      substringToEnd
    • v
      toLowerCase
    • v
      toLocaleLowerCase
    • v
      toUpperCase
    • v
      toLocaleUpperCase
    • v
      trim
    • v
      anchor
    • v
      link
    • v
      castToArrayLike

    © 2024 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on