Core
timeoutId
type timeoutId = Js.Global.timeoutId
An id
representing a timeout started via setTimeout
.
See setTimeout
on MDN.
setTimeout
let setTimeout: (unit => unit, int) => timeoutId
setTimeout(callback, durationInMilliseconds)
starts a timer that will execute callback
after durationInMilliseconds
.
See setTimeout
on MDN.
Examples
RESCRIPT// Log to the console after 2 seconds (2000 milliseconds).
let timeoutId = setTimeout(() => {
Console.log("This prints in 2 seconds.")
}, 2000)
setTimeoutFloat
let setTimeoutFloat: (unit => unit, float) => timeoutId
setTimeoutFloat(callback, durationInMilliseconds)
starts a timer that will execute callback
after durationInMilliseconds
.
The same as setTimeout
, but allows you to pass a float
instead of an int
for the duration.
See setTimeout
on MDN.
Examples
RESCRIPT// Log to the console after 2 seconds (2000 milliseconds).
let timeoutId = setTimeoutFloat(() => {
Console.log("This prints in 2 seconds.")
}, 2000.)
clearTimeout
let clearTimeout: timeoutId => unit
clearTimeout(timeoutId)
clears a scheduled timeout if it hasn't already executed.
See clearTimeout
on MDN.
Examples
RESCRIPTlet timeoutId = setTimeout(() => {
Console.log("This prints in 2 seconds.")
}, 2000)
// Clearing the timeout right away, before 2 seconds has passed, means that the above callback logging to the console will never run.
clearTimeout(timeoutId)
intervalId
type intervalId = Js.Global.intervalId
An id
representing an interval started via setInterval
.
See setInterval
on MDN.
setInterval
let setInterval: (unit => unit, int) => intervalId
setInterval(callback, intervalInMilliseconds)
starts an interval that will execute callback
every durationInMilliseconds
milliseconds.
See setInterval
on MDN.
Examples
RESCRIPT// Log to the console ever 2 seconds (2000 milliseconds).
let intervalId = setInterval(() => {
Console.log("This prints every 2 seconds.")
}, 2000)
setIntervalFloat
let setIntervalFloat: (unit => unit, float) => intervalId
setIntervalFloat(callback, intervalInMilliseconds)
starts an interval that will execute callback
every durationInMilliseconds
milliseconds.
The same as setInterval
, but allows you to pass a float
instead of an int
for the duration.
See setInterval
on MDN.
Examples
RESCRIPT// Log to the console ever 2 seconds (2000 milliseconds).
let intervalId = setIntervalFloat(() => {
Console.log("This prints every 2 seconds.")
}, 2000.)
clearInterval
let clearInterval: intervalId => unit
clearInterval(intervalId)
clears a scheduled interval.
See clearInterval
on MDN.
Examples
RESCRIPTlet intervalId = setInterval(() => {
Console.log("This prints in 2 seconds.")
}, 2000)
// Stop the interval after 10 seconds
let timeoutId = setTimeout(() => {
clearInterval(intervalId)
}, 10000)
encodeURI
let encodeURI: string => string
Encodes a URI by replacing characters in the provided string that aren't valid in a URL.
This is intended to operate on full URIs, so it encodes fewer characters than what encodeURIComponent
does.
If you're looking to encode just parts of a URI, like a query parameter, prefer encodeURIComponent
.
See encodeURI
on MDN.
Examples
RESCRIPTConsole.log(encodeURI("https://rescript-lang.org?array=[someValue]"))
// Logs "https://rescript-lang.org?array=%5BsomeValue%5D" to the console.
decodeURI
let decodeURI: string => string
Decodes a previously encoded URI back to a regular string.
This is intended to operate on full URIs, so it decodes fewer characters than what decodeURIComponent
does.
If you're looking to decode just parts of a URI, like a query parameter, prefer decodeURIComponent
.
See decodeURI
on MDN.
Examples
RESCRIPTConsole.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D"))
// Logs "https://rescript-lang.org?array=[someValue]" to the console.
encodeURIComponent
let encodeURIComponent: string => string
Encodes a string so it can be used as part of a URI.
See encodeURIComponent
on MDN.
Examples
RESCRIPTConsole.log(encodeURIComponent("array=[someValue]"))
// Logs "array%3D%5BsomeValue%5D" to the console.
decodeURIComponent
let decodeURIComponent: string => string
Decodes a previously URI encoded string back to its original form.
See decodeURIComponent
on MDN.
Examples
RESCRIPTConsole.log(decodeURIComponent("array%3D%5BsomeValue%5D"))
// Logs "array=[someValue]" to the console.
window
let window: Dom.window
document
let document: Dom.document
globalThis
let globalThis: {..}
null
let null: Core__Nullable.t<'a>
undefined
let undefined: Core__Nullable.t<'a>
typeof
let typeof: 'a => Core__Type.t
t
type t<'a> = Js.t<'a>
constraint 'a = {..}
null
type null<'a> = Js.null<'a>
undefined
type undefined<'a> = Js.undefined<'a>
nullable
type nullable<'a> = Js.nullable<'a>
panic
let panic: string => 'a