From 95178296b2225e419a34abfd8f145e24a7cfe7bb Mon Sep 17 00:00:00 2001 From: Glenn Slotte Date: Sun, 19 Feb 2023 15:49:00 +0100 Subject: [PATCH] Flesh out Console (#56) * feat(console): add six-argument variants * feat(console): add variadic variants * docs(console): fix typo in example, log2 -> log3 * style(math): formatting * style(array): formatting * feat(console): add assert * feat(console): add clear * feat(console): add count and countReset * feat(console): add debug and variants * feat(console): add dir * feat(console): add dirxml * refactor(console): organize bindings alphabetically * feat(console): add group/groupCollapsed/groupEnd * feat(console): add table * feat(console): add timeLog * docs(console): use lower-case for the console object name * docs(console): add blank line between paragraphs for readability. --- src/Core__Array.resi | 4 +- src/Core__Console.res | 71 +++-- src/Core__Console.resi | 615 +++++++++++++++++++++++++++++++++++------ src/Core__Math.resi | 134 ++++++--- 4 files changed, 682 insertions(+), 142 deletions(-) diff --git a/src/Core__Array.resi b/src/Core__Array.resi index 268faca4..e97aeaa0 100644 --- a/src/Core__Array.resi +++ b/src/Core__Array.resi @@ -104,7 +104,6 @@ let shuffle: array<'a> => array<'a> let shuffleInPlace: array<'a> => unit let flatMap: (array<'a>, 'a => array<'b>) => array<'b> - /** `at(array, index)` @@ -120,4 +119,5 @@ let flatMap: (array<'a>, 'a => array<'b>) => array<'b> ["a", "b", "c"]->Array.at(-4) // None ``` */ -@send external at: (array<'a>, int) => option<'a> = "at" +@send +external at: (array<'a>, int) => option<'a> = "at" diff --git a/src/Core__Console.res b/src/Core__Console.res index 8fefe380..2c85d024 100644 --- a/src/Core__Console.res +++ b/src/Core__Console.res @@ -1,28 +1,67 @@ -@val external log: 'a => unit = "console.log" -@val external log2: ('a, 'b) => unit = "console.log" -@val external log3: ('a, 'b, 'c) => unit = "console.log" -@val external log4: ('a, 'b, 'c, 'd) => unit = "console.log" -@val external log5: ('a, 'b, 'c, 'd, 'e) => unit = "console.log" +@val external assert_: (bool, 'a) => unit = "console.assert" +@val external assert2: (bool, 'a, 'b) => unit = "console.assert" +@val external assert3: (bool, 'a, 'b, 'c) => unit = "console.assert" +@val external assert4: (bool, 'a, 'b, 'c, 'd) => unit = "console.assert" +@val external assert5: (bool, 'a, 'b, 'c, 'd, 'e) => unit = "console.assert" +@val external assert6: (bool, 'a, 'b, 'c, 'd, 'e, 'f) => unit = "console.assert" +@val @variadic external assertMany: (bool, array<_>) => unit = "console.assert" -@val external info: 'a => unit = "console.info" -@val external info2: ('a, 'b) => unit = "console.info" -@val external info3: ('a, 'b, 'c) => unit = "console.info" -@val external info4: ('a, 'b, 'c, 'd) => unit = "console.info" -@val external info5: ('a, 'b, 'c, 'd, 'e) => unit = "console.info" +@val external clear: unit => unit = "console.clear" -@val external warn: 'a => unit = "console.warn" -@val external warn2: ('a, 'b) => unit = "console.warn" -@val external warn3: ('a, 'b, 'c) => unit = "console.warn" -@val external warn4: ('a, 'b, 'c, 'd) => unit = "console.warn" -@val external warn5: ('a, 'b, 'c, 'd, 'e) => unit = "console.warn" +@val external count: string => unit = "console.count" +@val external countReset: string => unit = "console.countReset" + +@val external debug: 'a => unit = "console.debug" +@val external debug2: ('a, 'b) => unit = "console.debug" +@val external debug3: ('a, 'b, 'c) => unit = "console.debug" +@val external debug4: ('a, 'b, 'c, 'd) => unit = "console.debug" +@val external debug5: ('a, 'b, 'c, 'd, 'e) => unit = "console.debug" +@val external debug6: ('a, 'b, 'c, 'd, 'e, 'f) => unit = "console.debug" +@val @variadic external debugMany: array<_> => unit = "console.debug" + +@val external dir: 'a => unit = "console.dir" +@val external dirxml: 'a => unit = "console.dirxml" @val external error: 'a => unit = "console.error" @val external error2: ('a, 'b) => unit = "console.error" @val external error3: ('a, 'b, 'c) => unit = "console.error" @val external error4: ('a, 'b, 'c, 'd) => unit = "console.error" @val external error5: ('a, 'b, 'c, 'd, 'e) => unit = "console.error" +@val external error6: ('a, 'b, 'c, 'd, 'e, 'f) => unit = "console.error" +@val @variadic external errorMany: array<_> => unit = "console.error" -@val external trace: unit => unit = "console.trace" +@val external group: string => unit = "console.group" +@val external groupCollapsed: string => unit = "console.groupCollapsed" +@val external groupEnd: unit => unit = "console.groupEnd" + +@val external info: 'a => unit = "console.info" +@val external info2: ('a, 'b) => unit = "console.info" +@val external info3: ('a, 'b, 'c) => unit = "console.info" +@val external info4: ('a, 'b, 'c, 'd) => unit = "console.info" +@val external info5: ('a, 'b, 'c, 'd, 'e) => unit = "console.info" +@val external info6: ('a, 'b, 'c, 'd, 'e, 'f) => unit = "console.info" +@val @variadic external infoMany: array<_> => unit = "console.info" + +@val external log: 'a => unit = "console.log" +@val external log2: ('a, 'b) => unit = "console.log" +@val external log3: ('a, 'b, 'c) => unit = "console.log" +@val external log4: ('a, 'b, 'c, 'd) => unit = "console.log" +@val external log5: ('a, 'b, 'c, 'd, 'e) => unit = "console.log" +@val external log6: ('a, 'b, 'c, 'd, 'e, 'f) => unit = "console.log" +@val @variadic external logMany: array<_> => unit = "console.log" + +@val external table: 'a => unit = "console.table" @val external time: string => unit = "console.time" @val external timeEnd: string => unit = "console.timeEnd" +@val external timeLog: string => unit = "console.timeLog" + +@val external trace: unit => unit = "console.trace" + +@val external warn: 'a => unit = "console.warn" +@val external warn2: ('a, 'b) => unit = "console.warn" +@val external warn3: ('a, 'b, 'c) => unit = "console.warn" +@val external warn4: ('a, 'b, 'c, 'd) => unit = "console.warn" +@val external warn5: ('a, 'b, 'c, 'd, 'e) => unit = "console.warn" +@val external warn6: ('a, 'b, 'c, 'd, 'e, 'f) => unit = "console.warn" +@val @variadic external warnMany: array<_> => unit = "console.warn" diff --git a/src/Core__Console.resi b/src/Core__Console.resi index 7aa5f7b5..41c7b9fc 100644 --- a/src/Core__Console.resi +++ b/src/Core__Console.resi @@ -1,211 +1,273 @@ /*** Functions for interacting with JavaScript console. -See: [`Console`](https://developer.mozilla.org/en-US/docs/Web/API/Console). + +See: [`console`](https://developer.mozilla.org/en-US/docs/Web/API/Console). */ /** -`log(value)` print a message to console. -See [`Console.log`](https://developer.mozilla.org/en-US/docs/Web/API/console/log) +`assert_(assertion, value)` print a message to console if `assertion` evaluates `false`. Does nothing if it's `true`. + +See [`console.assert`](https://developer.mozilla.org/en-US/docs/Web/API/console/assert) on MDN. ## Examples ```rescript -Console.log("Hello") -let obj = {"name": "ReScript", "version": 10} -Console.log(obj) +Console.assert_(false, "Hello World!") +Console.assert_(n == 42, "The answer") ``` */ @val -external log: 'a => unit = "console.log" +external assert_: (bool, 'a) => unit = "console.assert" /** -`log2(v1, v2)`. Like `log`, but with two arguments. +`assert2(v1, v2)`. Like `assert_`, but with two arguments. ## Examples ```rescript -Console.log2("Hello", "World") -Console.log2([1, 2, 3], '4') +Console.assert2(false, "Hello", "World") +Console.assert2(n == 42, [1, 2, 3], '4') ``` */ @val -external log2: ('a, 'b) => unit = "console.log" +external assert2: (bool, 'a, 'b) => unit = "console.assert" /** -`log3(v1, v2, v3)`. Like `log`, but with three arguments. +`assert3(v1, v2, v3)`. Like `assert_`, but with three arguments. ## Examples ```rescript -Console.log3("Hello", "World", "ReScript") -Console.log2("One", 2, #3) +Console.assert3(false, "Hello", "World", "ReScript") +Console.assert3(n == 42, "One", 2, #3) ``` */ @val -external log3: ('a, 'b, 'c) => unit = "console.log" +external assert3: (bool, 'a, 'b, 'c) => unit = "console.assert" + /** -`log4(v1, v2, v3, v4)`. Like `log`, but with four arguments. +`assert4(v1, v2, v3, v4)`. Like `assert_`, but with four arguments. ## Examples ```rescript -Console.log4("Hello", "World", "ReScript", "!!!") -Console.log4([1, 2], (3, 4), [#5, #6], #"polyvar") +Console.assert4(false, "Hello", "World", "ReScript", "!!!") +Console.assert4(m == 42, [1, 2], (3, 4), [#5, #6], #"polyvar") ``` */ @val -external log4: ('a, 'b, 'c, 'd) => unit = "console.log" +external assert4: (bool, 'a, 'b, 'c, 'd) => unit = "console.assert" /** -`log5(v1, v2, v3, v4, v5)`. Like `log`, but with five arguments. +`assert5(v1, v2, v3, v4, v5)`. Like `assert_`, but with five arguments. ## Examples ```rescript -Console.log5("Hello", "World", "JS", '!', '!') -Console.log5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +Console.assert5(false, "Hello", "World", "JS", '!', '!') +Console.assert5(n == 42, [1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) ``` */ @val -external log5: ('a, 'b, 'c, 'd, 'e) => unit = "console.log" +external assert5: (bool, 'a, 'b, 'c, 'd, 'e) => unit = "console.assert" + /** -`info(value)` print an informational message to console. -See [`Console.info`](https://developer.mozilla.org/en-US/docs/Web/API/console/info) -on MDN. +`assert6(v1, v2)`. Like `assert_`, but with six arguments. ## Examples ```rescript -Console.info("Information") -Console.info(("Hello", "JS")) +Console.assert6(false, "Hello", "World", "JS", '!', '!', '?') +Console.assert6(n == 42, [1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) ``` */ @val -external info: 'a => unit = "console.info" +external assert6: (bool, 'a, 'b, 'c, 'd, 'e, 'f) => unit = "console.assert" /** -`info2(v1, v2)`. Like `info`, but with two arguments. +`assertMany(assertion, arr)`. Like `assert_`, but variadic. ## Examples ```rescript -Console.info2("Info", "failed to download") -Console.info2(#info, {"name": "ReScript"}) +Console.assertMany(false, ["Hello", "World"]) +Console.assertMany(n == 42, [1, 2, 3]) ``` */ @val -external info2: ('a, 'b) => unit = "console.info" +@variadic +external assertMany: (bool, array<_>) => unit = "console.assert" /** -`info3(v1, v2, v3)`. Like `info`, but with three arguments. +`clear()` clears the console, if allowed. + +See [`console.clear`](https://developer.mozilla.org/en-US/docs/Web/API/console/clear) +on MDN. ## Examples ```rescript -Console.info3("Hello", "World", "ReScript") -Console.info3([1, 2, 3], #4, #5) +Console.clear() ``` */ @val -external info3: ('a, 'b, 'c) => unit = "console.info" +external clear: unit => unit = "console.clear" /** -`info4(v1, v2, v3, v4)`. Like `info`, but with four arguments. +`count(label)` prints to the console the number of times it's been called with the given label. + +See [`console.count`](https://developer.mozilla.org/en-US/docs/Web/API/console/count) +on MDN. ## Examples ```rescript -Console.info4("Hello", "World", "ReScript", '!') -Console.info4([1, 2, 3], #4, #5, #lastinfo) +Console.count("rescript") ``` */ @val -external info4: ('a, 'b, 'c, 'd) => unit = "console.info" +external count: string => unit = "console.count" /** -`info5(v1, v2, v3, v4, v5)`. Like `info`, but with five arguments. +`countReset(label)` resets the count for the given label to 0. + +See [`console.countReset`](https://developer.mozilla.org/en-US/docs/Web/API/console/countReset) +on MDN. ## Examples ```rescript -Console.info5("Hello", "World", "from", "JS", "!!!") -Console.info5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +Console.countReset("rescript") ``` */ @val -external info5: ('a, 'b, 'c, 'd, 'e) => unit = "console.info" +external countReset: string => unit = "console.countReset" /** -`warn(value)` print a warning message to console. -See [`Console.warn`](https://developer.mozilla.org/en-US/docs/Web/API/console/warn) +`debug(value)` print a debug message to console. + +See [`console.debug`](https://developer.mozilla.org/en-US/docs/Web/API/console/debug) on MDN. ## Examples ```rescript -Console.warn("Warning") -Console.warn(("Warning", "invalid number")) +Console.debug("Hello") +let obj = {"name": "ReScript", "version": 10} +Console.debug(obj) ``` */ @val -external warn: 'a => unit = "console.warn" +external debug: 'a => unit = "console.debug" /** -`warn2(v1, v2)`. Like `warn`, but two arguments. +`debug2(v1, v2)`. Like `debug`, but with two arguments. ## Examples ```rescript -Console.warn2("Hello", "World") -Console.warn2([1, 2, 3], 4) +Console.debug2("Hello", "World") +Console.debug2([1, 2, 3], '4') ``` */ @val -external warn2: ('a, 'b) => unit = "console.warn" +external debug2: ('a, 'b) => unit = "console.debug" /** -`warn3(v1, v2, v3)`. Like `warn`, but three arguments. +`debug3(v1, v2, v3)`. Like `debug`, but with three arguments. ## Examples ```rescript -Console.warn3("Hello", "World", "ReScript") -Console.warn3([1, 2, 3], #4, #5) +Console.debug3("Hello", "World", "ReScript") +Console.debug3("One", 2, #3) ``` */ @val -external warn3: ('a, 'b, 'c) => unit = "console.warn" +external debug3: ('a, 'b, 'c) => unit = "console.debug" /** -`warn4(v1, v2, v3, v4)`. Like `warn`, but with four arguments. +`debug4(v1, v2, v3, v4)`. Like `debug`, but with four arguments. ## Examples ```rescript -Console.warn4("Hello", "World", "ReScript", "!!!") -Console.warn4(#first, #second, #third, ("fourth")) +Console.debug4("Hello", "World", "ReScript", "!!!") +Console.debug4([1, 2], (3, 4), [#5, #6], #"polyvar") ``` */ @val -external warn4: ('a, 'b, 'c, 'd) => unit = "console.warn" +external debug4: ('a, 'b, 'c, 'd) => unit = "console.debug" /** -`warn5(v1, v2, v3, v4, v5)`. Like `warn`, but with five arguments. +`debug5(v1, v2, v3, v4, v5)`. Like `debug`, but with five arguments. ## Examples ```rescript -Console.warn5("Hello", "World", "from", "JS", "!!!") -Console.warn5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +Console.debug5("Hello", "World", "JS", '!', '!') +Console.debug5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) ``` */ @val -external warn5: ('a, 'b, 'c, 'd, 'e) => unit = "console.warn" +external debug5: ('a, 'b, 'c, 'd, 'e) => unit = "console.debug" + +/** +`debug6(v1, v2, v3, v4, v5, v6)`. Like `debug`, but with six arguments. + +## Examples + +```rescript +Console.debug6("Hello", "World", "JS", '!', '!', '?') +Console.debug6([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +``` +*/ +@val +external debug6: ('a, 'b, 'c, 'd, 'e, 'f) => unit = "console.debug" + +/** +`debugMany(arr)`. Like `debug`, but variadic. + +## Examples + +```rescript +Console.debugMany(["Hello", "World"]) +Console.debugMany([1, 2, 3]) +``` +*/ +@val +@variadic +external debugMany: array<_> => unit = "console.debug" + +/** +`dir(object)` displays an interactive view of the object in the console. + +See [`console.dir`](https://developer.mozilla.org/en-US/docs/Web/API/console/dir) +on MDN. + +## Examples + +```rescript +Console.dir({"language": "rescript", "version": 10.1.2}) +``` +*/ +@val +external dir: 'a => unit = "console.dir" + +/** +`dirxml(object)` displays an interactive tree view of an XML/HTML element in the console. + +See [`console.dirxml`](https://developer.mozilla.org/en-US/docs/Web/API/console/dirxml) +on MDN. +*/ +@val +external dirxml: 'a => unit = "console.dirxml" /** `error(value)` prints an error message to console. -See [`Console.error`](https://developer.mozilla.org/en-US/docs/Web/API/console/error) + +See [`console.error`](https://developer.mozilla.org/en-US/docs/Web/API/console/error) on MDN. ## Examples @@ -271,30 +333,282 @@ Console.error5(1, #second, #third, ("fourth"), 'c') external error5: ('a, 'b, 'c, 'd, 'e) => unit = "console.error" /** -`trace()` print a stack trace to console. -See [`Console.trace`](https://developer.mozilla.org/en-US/docs/Web/API/console/trace) +`error6(v1, v2, v3, v4, v5, v6)`. Like `error`, but with six arguments. + +## Examples + +```rescript +Console.error6("Hello", "World", "from", "JS", "!!!", '!') +Console.error6([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +``` +*/ +@val +external error6: ('a, 'b, 'c, 'd, 'e, 'f) => unit = "console.error" + +/** +`group(label)` creates a new "group" level with the given label. + +See [`console.group`](https://developer.mozilla.org/en-US/docs/Web/API/console/group) on MDN. +## Example + +```rescript +Console.group("first group") +Console.group("second group") +Console.log("a message on the second level") +Console.groupEnd() +Console.log("a message message on the first level") +Console.groupEnd() +``` +*/ +@val +external group: string => unit = "console.group" + +/** +`groupCollapsed(label)`. Like `group` but collapses the group initially. + +See [`console.groupCollapsed`](https://developer.mozilla.org/en-US/docs/Web/API/console/groupCollapsed) +on MDN. +*/ +@val +external groupCollapsed: string => unit = "console.groupCollapsed" + +/** +`groupEnd()` ends the current group. + +See [`console.groupEnd`](https://developer.mozilla.org/en-US/docs/Web/API/console/groupEnd) +on MDN. +*/ +@val +external groupEnd: unit => unit = "console.groupEnd" + +/** +`errorMany(arr)`. Like `error`, but variadic. + ## Examples ```rescript -let main = () => { - Console.trace() -} -main() -// In the console, the following trace will be displayed: -// main -// +Console.errorMany(["Hello", "World"]) +Console.errorMany([1, 2, 3]) ``` */ @val -external trace: unit => unit = "console.trace" +@variadic +external errorMany: array<_> => unit = "console.error" + +/** +`info(value)` print an informational message to console. + +See [`console.info`](https://developer.mozilla.org/en-US/docs/Web/API/console/info) +on MDN. + +## Examples + +```rescript +Console.info("Information") +Console.info(("Hello", "JS")) +``` +*/ +@val +external info: 'a => unit = "console.info" + +/** +`info2(v1, v2)`. Like `info`, but with two arguments. + +## Examples + +```rescript +Console.info2("Info", "failed to download") +Console.info2(#info, {"name": "ReScript"}) +``` +*/ +@val +external info2: ('a, 'b) => unit = "console.info" + +/** +`info3(v1, v2, v3)`. Like `info`, but with three arguments. + +## Examples + +```rescript +Console.info3("Hello", "World", "ReScript") +Console.info3([1, 2, 3], #4, #5) +``` +*/ +@val +external info3: ('a, 'b, 'c) => unit = "console.info" + +/** +`info4(v1, v2, v3, v4)`. Like `info`, but with four arguments. + +## Examples + +```rescript +Console.info4("Hello", "World", "ReScript", '!') +Console.info4([1, 2, 3], #4, #5, #lastinfo) +``` +*/ +@val +external info4: ('a, 'b, 'c, 'd) => unit = "console.info" + +/** +`info5(v1, v2, v3, v4, v5)`. Like `info`, but with five arguments. + +## Examples + +```rescript +Console.info5("Hello", "World", "from", "JS", "!!!") +Console.info5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +``` +*/ +@val +external info5: ('a, 'b, 'c, 'd, 'e) => unit = "console.info" + +/** +`info6(v1, v2, v3, v4, v5, v6)`. Like `info`, but with six arguments. + +## Examples + +```rescript +Console.info6("Hello", "World", "from", "JS", "!!!", '!') +Console.info6([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +``` +*/ +@val +external info6: ('a, 'b, 'c, 'd, 'e, 'f) => unit = "console.info" + +/** +`infoMany(arr)`. Like `info`, but variadic. + +## Examples + +```rescript +Console.infoMany(["Hello", "World"]) +Console.infoMany([1, 2, 3]) +``` +*/ +@val +@variadic +external infoMany: array<_> => unit = "console.info" + +/** +`log(value)` print a message to console. + +See [`console.log`](https://developer.mozilla.org/en-US/docs/Web/API/console/log) +on MDN. + +## Examples + +```rescript +Console.log("Hello") +let obj = {"name": "ReScript", "version": 10} +Console.log(obj) +``` +*/ +@val +external log: 'a => unit = "console.log" + +/** +`log2(v1, v2)`. Like `log`, but with two arguments. + +## Examples + +```rescript +Console.log2("Hello", "World") +Console.log2([1, 2, 3], '4') +``` +*/ +@val +external log2: ('a, 'b) => unit = "console.log" + +/** +`log3(v1, v2, v3)`. Like `log`, but with three arguments. + +## Examples + +```rescript +Console.log3("Hello", "World", "ReScript") +Console.log3("One", 2, #3) +``` +*/ +@val +external log3: ('a, 'b, 'c) => unit = "console.log" + +/** +`log4(v1, v2, v3, v4)`. Like `log`, but with four arguments. + +## Examples + +```rescript +Console.log4("Hello", "World", "ReScript", "!!!") +Console.log4([1, 2], (3, 4), [#5, #6], #"polyvar") +``` +*/ +@val +external log4: ('a, 'b, 'c, 'd) => unit = "console.log" + +/** +`log5(v1, v2, v3, v4, v5)`. Like `log`, but with five arguments. + +## Examples + +```rescript +Console.log5("Hello", "World", "JS", '!', '!') +Console.log5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +``` +*/ +@val +external log5: ('a, 'b, 'c, 'd, 'e) => unit = "console.log" + +/** +`log6(v1, v2, v3, v4, v5, v6)`. Like `log`, but with six arguments. + +## Examples + +```rescript +Console.log6("Hello", "World", "JS", '!', '!', '?') +Console.log6([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +``` +*/ +@val +external log6: ('a, 'b, 'c, 'd, 'e, 'f) => unit = "console.log" + +/** +`logMany(arr)`. Like `log`, but variadic. + +## Examples + +```rescript +Console.logMany(["Hello", "World"]) +Console.logMany([1, 2, 3]) +``` +*/ +@val +@variadic +external logMany: array<_> => unit = "console.log" + +/** +`table(object)` displays an tabular view of the object in the console. + +See [`console.table`](https://developer.mozilla.org/en-US/docs/Web/API/console/table) +on MDN. + +## Examples + +```rescript +Console.table({"language": "rescript", "version": 10.1.2}) +``` +*/ +@val +external table: 'a => unit = "console.table" /** `time(label)` creates a timer to measure how long an operation takes. `label` -must be a unique name. Call `Console.timeEnd` with the same `label` to print -output time. -See [`Console.time`](https://developer.mozilla.org/en-US/docs/Web/API/console/time) +must be a unique name. Call `console.timeEnd` with the same `label` to print +output time. + +See [`console.time`](https://developer.mozilla.org/en-US/docs/Web/API/console/time) on MDN. ## Examples @@ -303,6 +617,7 @@ on MDN. Console.time("for_time") for x in 3 downto 1 { Console.log(x) + Console.timeLog("for_time") } Console.timeEnd("for_time") ``` @@ -312,7 +627,8 @@ external time: string => unit = "console.time" /** `timeEnd(label)` stops a timer created by `time`. -See [`Console.timeEnd`](https://developer.mozilla.org/en-US/docs/Web/API/console/timeEnd) + +See [`console.timeEnd`](https://developer.mozilla.org/en-US/docs/Web/API/console/timeEnd) on MDN. ## Examples @@ -321,9 +637,146 @@ on MDN. Console.time("for_time") for x in 3 downto 1 { Console.log(x) + Console.timeLog("for_time") } Console.timeEnd("for_time") ``` */ @val external timeEnd: string => unit = "console.timeEnd" + +/** +`timeLog(label)` prints the current elapsed time of the given timer to the console. + +See [`console.timeLog`](https://developer.mozilla.org/en-US/docs/Web/API/console/timeLog) +on MDN. + +## Examples + +```rescript +Console.time("for_time") +for x in 3 downto 1 { + Console.log(x) + Console.timeLog("for_time") +} +Console.timeEnd("for_time") +``` +*/ +@val +external timeLog: string => unit = "console.timeLog" + +/** +`trace()` print a stack trace to console. + +See [`console.trace`](https://developer.mozilla.org/en-US/docs/Web/API/console/trace) +on MDN. + +## Examples + +```rescript +let main = () => { + Console.trace() +} +main() +// In the console, the following trace will be displayed: +// main +// +``` +*/ +@val +external trace: unit => unit = "console.trace" + +/** +`warn(value)` print a warning message to console. + +See [`console.warn`](https://developer.mozilla.org/en-US/docs/Web/API/console/warn) +on MDN. + +## Examples + +```rescript +Console.warn("Warning") +Console.warn(("Warning", "invalid number")) +``` +*/ +@val +external warn: 'a => unit = "console.warn" + +/** +`warn2(v1, v2)`. Like `warn`, but two arguments. + +## Examples + +```rescript +Console.warn2("Hello", "World") +Console.warn2([1, 2, 3], 4) +``` +*/ +@val +external warn2: ('a, 'b) => unit = "console.warn" + +/** +`warn3(v1, v2, v3)`. Like `warn`, but three arguments. + +## Examples + +```rescript +Console.warn3("Hello", "World", "ReScript") +Console.warn3([1, 2, 3], #4, #5) +``` +*/ +@val +external warn3: ('a, 'b, 'c) => unit = "console.warn" + +/** +`warn4(v1, v2, v3, v4)`. Like `warn`, but with four arguments. + +## Examples + +```rescript +Console.warn4("Hello", "World", "ReScript", "!!!") +Console.warn4(#first, #second, #third, ("fourth")) +``` +*/ +@val +external warn4: ('a, 'b, 'c, 'd) => unit = "console.warn" + +/** +`warn5(v1, v2, v3, v4, v5)`. Like `warn`, but with five arguments. + +## Examples + +```rescript +Console.warn5("Hello", "World", "from", "JS", "!!!") +Console.warn5([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}) +``` +*/ +@val +external warn5: ('a, 'b, 'c, 'd, 'e) => unit = "console.warn" + +/** +`warn6(v1, v2, v3, v4, v5, v6)`. Like `warn`, but with six arguments. + +## Examples + +```rescript +Console.warn6("Hello", "World", "from", "JS", "!!!", '!') +Console.warn6([1, 2], (3, 4), [#5, #6], #"polyvar", {"name": "ReScript"}, 42) +``` +*/ +@val +external warn6: ('a, 'b, 'c, 'd, 'e, 'f) => unit = "console.warn" + +/** +`warnMany(arr)`. Like `warn`, but variadic. + +## Examples + +```rescript +Console.warnMany(["Hello", "World"]) +Console.warnMany([1, 2, 3]) +``` +*/ +@val +@variadic +external warnMany: array<_> => unit = "console.warn" diff --git a/src/Core__Math.resi b/src/Core__Math.resi index 5394a636..00cd21b6 100644 --- a/src/Core__Math.resi +++ b/src/Core__Math.resi @@ -182,7 +182,8 @@ module Int: { Math.Int.imul(-5, 12) // 60 ``` */ - @val external imul: (int, int) => int = "Math.imul" + @val + external imul: (int, int) => int = "Math.imul" /** `min(a, b)` returns the minimum of its two integer arguments. @@ -195,7 +196,8 @@ module Int: { Math.Int.min(-1, -2) // -2 ``` */ - @val external min: (int, int) => int = "Math.min" + @val + external min: (int, int) => int = "Math.min" /** `minMany(arr)` returns the minimum of the integers in the given array `arr`. @@ -210,7 +212,9 @@ module Int: { Math.Int.minMany([])->Float.isFinite // false ``` */ - @variadic @val external minMany: array => int = "Math.min" + @variadic + @val + external minMany: array => int = "Math.min" /** `max(a, b)` returns the maximum of its two integer arguments. @@ -223,7 +227,8 @@ module Int: { Math.Int.max(-1, -2) // -1 ``` */ - @val external max: (int, int) => int = "Math.max" + @val + external max: (int, int) => int = "Math.max" /** `maxMany(arr)` returns the maximum of the integers in the given array `arr`. @@ -238,7 +243,9 @@ module Int: { Math.Int.maxMany([])->Float.isFinite // false ``` */ - @variadic @val external maxMany: array => int = "Math.max" + @variadic + @val + external maxMany: array => int = "Math.max" /** `pow(a, ~exp)` raises the given base `a` to the given exponent `exp`. @@ -251,7 +258,8 @@ module Int: { Math.Int.pow(3, ~exp=4) // 81 ``` */ - @val external pow: (int, ~exp: int) => int = "Math.pow" + @val + external pow: (int, ~exp: int) => int = "Math.pow" /** `sign(v)` returns the sign of its integer argument: `-1` if negative, `0` if @@ -266,7 +274,8 @@ module Int: { Math.Int.sign(0) // 0 ``` */ - @val external sign: int => int = "Math.sign" + @val + external sign: int => int = "Math.sign" } /** @@ -280,7 +289,8 @@ Math.abs(-2.0) // 2.0 Math.abs(3.0) // 3.0 ``` */ -@val external abs: float => float = "Math.abs" +@val +external abs: float => float = "Math.abs" /** `acos(v)` returns arccosine (in radians) of argument `v`, returns `NaN` if the @@ -294,7 +304,8 @@ Math.acos(-1) // 3.141592653589793 Math.acos(-3)->Float.isNaN // true ``` */ -@val external acos: float => float = "Math.acos" +@val +external acos: float => float = "Math.acos" /** `acosh(v)` returns the inverse hyperbolic arccosine (in radians) of argument `v`, @@ -308,7 +319,8 @@ Math.acosh(1) // 0.0 Math.acosh(0.5)->Float.isNaN // true ``` */ -@val external acosh: float => float = "Math.acosh" +@val +external acosh: float => float = "Math.acosh" /** `asin(v)` returns the inverse sine (in radians) of argument `v`, returns `NaN` @@ -322,7 +334,8 @@ Math.asin(-1.0) // -1.5707963267948966 Math.asin(-2.0)->Float.isNaN // true ``` */ -@val external asin: float => float = "Math.asin" +@val +external asin: float => float = "Math.asin" /** `asinh(v)` returns the inverse hyperbolic sine of argument `v`. @@ -335,7 +348,8 @@ Math.asinh(-1) // -0.881373587019543 Math.asinh(-0) // -0.0 ``` */ -@val external asinh: float => float = "Math.asinh" +@val +external asinh: float => float = "Math.asinh" /** `atan(v)` returns the inverse tangent (in radians) of argument `v`. @@ -349,7 +363,8 @@ Math.atan(0.0) // 0.0 Math.atan(1) // 0.7853981633974483 ``` */ -@val external atan: float => float = "Math.atan" +@val +external atan: float => float = "Math.atan" /** `atanh(v)` returns the invert hyperbolic tangent of argument `v`. Returns `NaN` @@ -367,7 +382,8 @@ Math.atanh(0.0) // 0.0 Math.atanh(0.5) // 0.5493061443340548 ``` */ -@val external atanh: float => float = "Math.atanh" +@val +external atanh: float => float = "Math.atanh" /** `atan2(~x, ~y)` returns the angle (in radians) of the quotient `y /. x`. It is @@ -383,7 +399,8 @@ Math.atan2(~x=90.0, ~y=15.0) // 1.4056476493802699 Math.atan2(~x=15.0, ~y=90.0) // 0.16514867741462683 ``` */ -@val external atan2: (~x: float, ~y: float) => float = "Math.atan2" +@val +external atan2: (~x: float, ~y: float) => float = "Math.atan2" /** `cbrt(v)` returns the cube root of argument `v`. @@ -397,7 +414,8 @@ Math.cbrt(-0.0) // -0.0 Math.cbrt(0.0) // 0.0 ``` */ -@val external cbrt: float => float = "Math.cbrt" +@val +external cbrt: float => float = "Math.cbrt" /** `ceil(v)` returns the smallest integral value greater than or equal to the @@ -414,7 +432,8 @@ Math.ceil(-3.1) == -3.0 Math.ceil(2_150_000_000.3) == 2_150_000_001.0 ``` */ -@val external ceil: float => float = "Math.ceil" +@val +external ceil: float => float = "Math.ceil" /** `cos(v)` returns the cosine of argument `v`, which must be specified in radians. @@ -428,7 +447,8 @@ Math.cos(0.0) // 1.0 Math.cos(1.0) // 0.5403023058681398 ``` */ -@val external cos: float => float = "Math.cos" +@val +external cos: float => float = "Math.cos" /** `cosh(v)` returns the hyperbolic cosine of argument `v`, which must be specified @@ -443,7 +463,8 @@ Math.cosh(-0.0) // 1.0 Math.cosh(0.0) // 1.0 ``` */ -@val external cosh: float => float = "Math.cosh" +@val +external cosh: float => float = "Math.cosh" /** `exp(v)` returns natural exponentional, returns *e* (the base of natural logarithms) @@ -457,7 +478,8 @@ Math.exp(-1.0) // 0.36787944117144233 Math.exp(0.0) // 1.0 ``` */ -@val external exp: float => float = "Math.exp" +@val +external exp: float => float = "Math.exp" /** `expm1(v)` returns *e* (the base of natural logarithms) to the power of the given @@ -471,7 +493,8 @@ Math.expm1(-1.0) // -0.6321205588285577 Math.expm1(-0.0) // -0 ``` */ -@val external expm1: float => float = "Math.expm1" +@val +external expm1: float => float = "Math.expm1" /** `floor(v)` returns the largest integral value less than or equal to the argument @@ -486,7 +509,8 @@ Math.floor(-45.05) // -46.0 Math.floor(-0.0) // -0.0 ``` */ -@val external floor: float => float = "Math.floor" +@val +external floor: float => float = "Math.floor" /** `fround(v)` returns the nearest single precision float. @@ -499,7 +523,8 @@ Math.fround(5.5) == 5.5 Math.fround(5.05) == 5.050000190734863 ``` */ -@val external fround: float => float = "Math.fround" +@val +external fround: float => float = "Math.fround" /** `hypot(a, b)` returns the square root of the sum of squares of its two arguments @@ -513,7 +538,8 @@ Math.hypot(3.0, 4.0) // 5.0 Math.hypot(3.0, 5.0) // 5.8309518948453 ``` */ -@val external hypot: (float, float) => float = "Math.hypot" +@val +external hypot: (float, float) => float = "Math.hypot" /** `hypotMany(arr)` returns the square root of the sum of squares of the numbers in @@ -528,7 +554,9 @@ Math.hypot([3.0, 4.0, 5.0]) // 7.0710678118654755 Math.hypot([]) // 0.0 ``` */ -@variadic @val external hypotMany: array => float = "Math.hypot" +@variadic +@val +external hypotMany: array => float = "Math.hypot" /** `log(v)` returns the natural logarithm of argument `v`, this is the number *x* @@ -545,7 +573,8 @@ Math.log(0.0)->Float.isFinite // false Math.log(1.0) // 0 ``` */ -@val external log: float => float = "Math.log" +@val +external log: float => float = "Math.log" /** `log1p(v)` returns the natural logarithm of one plus the argument `v`. @@ -560,7 +589,8 @@ Math.log1p(-1.0)->Float.isFinite // false Math.log1p(-0.0) // -0 ``` */ -@val external log1p: float => float = "Math.log1p" +@val +external log1p: float => float = "Math.log1p" /** `log10(v)` returns the base 10 logarithm of argument `v`. Returns `NaN` for @@ -576,7 +606,8 @@ Math.log10(0.0)->Float.isFinite // false Math.log10(1.0) // 0 ``` */ -@val external log10: float => float = "Math.log10" +@val +external log10: float => float = "Math.log10" /** `log2(v)` returns the base 2 logarithm of argument `v`. Returns `NaN` for @@ -592,7 +623,8 @@ Math.log2(0.0)->Float.isFinite // false Math.log2(1.0) // 0.0 ``` */ -@val external log2: float => float = "Math.log2" +@val +external log2: float => float = "Math.log2" /** `min(a, b)` returns the minimum of its two float arguments. @@ -605,7 +637,8 @@ Math.min(1.0, 2.0) // 1.0 Math.min(-1.0, -2.0) // -2.0 ``` */ -@val external min: (float, float) => float = "Math.min" +@val +external min: (float, float) => float = "Math.min" /** `minMany(arr)` returns the minimum of the float in the given array `arr`. @@ -620,7 +653,9 @@ Math.minMany([-1.0, -2.0]) // -2.0 Math.minMany([])->Float.isFinite // false ``` */ -@variadic @val external minMany: array => float = "Math.min" +@variadic +@val +external minMany: array => float = "Math.min" /** `max(a, b)` returns the maximum of its two float arguments. @@ -633,7 +668,8 @@ Math.max(1.0, 2.0) // 2.0 Math.max(-1.0, -2.0) // -1.0 ``` */ -@val external max: (float, float) => float = "Math.max" +@val +external max: (float, float) => float = "Math.max" /** `maxMany(arr)` returns the maximum of the float in the given array `arr`. @@ -648,7 +684,9 @@ Math.maxMany([-1.0, -2.0]) // -1.0 Math.maxMany([])->Float.isFinite // false ``` */ -@variadic @val external maxMany: array => float = "Math.max" +@variadic +@val +external maxMany: array => float = "Math.max" /** `pow(a, ~exp)` raises the given base `a` to the given exponent `exp`. @@ -661,7 +699,8 @@ Math.pow(2.0, ~exp=4.0) // 16.0 Math.pow(3.0, ~exp=4.0) // 81.0 ``` */ -@val external pow: (float, ~exp: float) => float = "Math.pow" +@val +external pow: (float, ~exp: float) => float = "Math.pow" /** `random()` returns a random number in the half-closed interval [0,1]. @@ -673,7 +712,8 @@ See [`Math.random`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe Math.random() ``` */ -@val external random: unit => float = "Math.random" +@val +external random: unit => float = "Math.random" /** `round(v)` returns then value of `v` rounded to nearest integral value @@ -691,7 +731,8 @@ Math.round(0.0) // 0.0 Math.round(-0.0) // -0.0 ``` */ -@val external round: float => float = "Math.round" +@val +external round: float => float = "Math.round" /** `sign(v)` returns the sign of its foat argument: `-1` if negative, `0` if @@ -706,7 +747,8 @@ Math.sign(-3.0) // 1.0 Math.sign(0.0) // 0.0 ``` */ -@val external sign: float => float = "Math.sign" +@val +external sign: float => float = "Math.sign" /** `sin(v)` returns the sine of argument `v`, which must be specified in radians. @@ -720,7 +762,8 @@ Math.sin(0.0) // 0.0 Math.sin(1.0) // 0.8414709848078965 ``` */ -@val external sin: float => float = "Math.sin" +@val +external sin: float => float = "Math.sin" /** `sinh(v)` returns then hyperbolic sine of argument `v`, which must be specified @@ -735,7 +778,8 @@ Math.sinh(0.0) // 0.0 Math.sinh(1.0) // 1.1752011936438014 ``` */ -@val external sinh: float => float = "Math.sinh" +@val +external sinh: float => float = "Math.sinh" /** `sqrt(v)` returns the square root of `v`. If `v` is negative returns `NaN`. @@ -751,7 +795,8 @@ Math.sqrt(1.0) // 1.0 Math.sqrt(9.0) // 3.0 ``` */ -@val external sqrt: float => float = "Math.sqrt" +@val +external sqrt: float => float = "Math.sqrt" /** `tan(v)` returns the tangent of argument `v`, which must be specified in @@ -766,7 +811,8 @@ Math.tan(0.0) // 0.0 Math.tan(1.0) // 1.5574077246549023 ``` */ -@val external tan: float => float = "Math.tan" +@val +external tan: float => float = "Math.tan" /** `tanh(v)` returns the hyperbolic tangent of argument `v`, which must be @@ -781,7 +827,8 @@ Math.tanh(0.0) // 0.0 Math.tanh(1.0) // 0.7615941559557649 ``` */ -@val external tanh: float => float = "Math.tanh" +@val +external tanh: float => float = "Math.tanh" /** `trunc(v)` truncates the argument `v`, i.e., removes fractional digits. @@ -796,4 +843,5 @@ Math.trunc(13.37) // 13.0 Math.trunc(42.84) // 42.0 ``` */ -@val external trunc: float => float = "Math.trunc" +@val +external trunc: float => float = "Math.trunc"