Wrapper for the console object for the JavaScript backend.
Styled Messages
CSS-styled messages in the browser are useful for debugging purposes. To use them, prefix the message with one or more %c, and provide the CSS style as the last argument. The amount of %c’s must match the amount of CSS-styled strings.
Example: cmd: -r:off
import std/jsconsole
console.log "%c My Debug Message", "color: red" # Notice the "%c"
console.log "%c My Debug %c Message", "color: red", "font-size: 2em"
Imports
Types
Console = ref object of JsRoot
Vars
console {.importc, nodecl.}: Console
Procs
proc clear(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/clear Source Edit
proc count(console: Console; label = "".cstring) {.importcpp, ...raises: [],
tags: [], forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/count Source Edit
proc countReset(console: Console; label = "".cstring) {.importcpp, ...raises: [],
tags: [], forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/countReset Source Edit
proc debug(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/debug Source Edit
func dir(console: Console; obj: auto) {.importcpp, ...raises: [], tags: [],
forbids: [].}
https://developer.mozilla.org/en-US/docs/Web/API/Console/dir Source Edit
func dirxml(console: Console; obj: auto) {.importcpp, ...raises: [], tags: [],
forbids: [].}
https://developer.mozilla.org/en-US/docs/Web/API/Console/dirxml Source Edit
proc error(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/error Source Edit
proc group(console: Console; label = "".cstring) {.importcpp, ...raises: [],
tags: [], forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/group Source Edit
proc groupCollapsed(console: Console; label = "".cstring) {.importcpp,
...raises: [], tags: [], forbids: [].}
https://developer.mozilla.org/en-US/docs/Web/API/Console/groupCollapsed Source Edit
proc groupEnd(console: Console) {.importcpp, ...raises: [], tags: [], forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/groupEnd Source Edit
proc info(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/info Source Edit
proc log(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/log Source Edit
proc table(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/table Source Edit
proc time(console: Console; label = "".cstring) {.importcpp, ...raises: [],
tags: [], forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/time Source Edit
proc timeEnd(console: Console; label = "".cstring) {.importcpp, ...raises: [],
tags: [], forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/timeEnd Source Edit
proc timeLog(console: Console; label = "".cstring) {.importcpp, ...raises: [],
tags: [], forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/timeLog Source Edit
func timeStamp(console: Console; label: cstring) {.importcpp, ...raises: [],
tags: [], forbids: [].}
https://developer.mozilla.org/en-US/docs/Web/API/Console/timeStamp
..warning:: non-standard
proc trace(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/trace Source Edit
proc warn(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
forbids: [].}
https://developer.mozilla.org/docs/Web/API/Console/warn Source Edit
Templates
template exception(console: Console; args: varargs[untyped])
Alias for console.error(). Source Edit
template jsAssert(console: Console; assertion)
JavaScript console.assert, for NodeJS this prints to stderr, assert failure just prints to console and do not quit the program, this is not meant to be better or even equal than normal assertions, is just for when you need faster performance and assertions, otherwise use the normal assertions for better user experience. https://developer.mozilla.org/en-US/docs/Web/API/Console/assert
Example:
console.jsAssert(42 == 42) # OK
console.jsAssert(42 != 42) # Fail, prints "Assertion failed" and continues
console.jsAssert('`' == '\n' and '\t' == '\0') # Message correctly formatted
assert 42 == 42 # Normal assertions keep working