Source   Edit

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"


Console = ref object of JsRoot
  Source   Edit


proc log(console: Console) {.importcpp, varargs.}   Source   Edit
proc debug(console: Console) {.importcpp, varargs.}   Source   Edit
proc info(console: Console) {.importcpp, varargs.}   Source   Edit
proc error(console: Console) {.importcpp, varargs.}   Source   Edit
proc trace(console: Console) {.importcpp, varargs.}   Source   Edit
proc warn(console: Console) {.importcpp, varargs.}   Source   Edit
proc clear(console: Console) {.importcpp, varargs.}   Source   Edit
proc count(console: Console; label = "".cstring) {.importcpp.}   Source   Edit
proc countReset(console: Console; label = "".cstring) {.importcpp.}   Source   Edit
proc group(console: Console; label = "".cstring) {.importcpp.}   Source   Edit
proc groupCollapsed(console: Console; label = "".cstring) {.importcpp.}   Source   Edit
proc groupEnd(console: Console) {.importcpp.}   Source   Edit
proc time(console: Console; label = "".cstring) {.importcpp.}   Source   Edit
proc timeEnd(console: Console; label = "".cstring) {.importcpp.}   Source   Edit
proc timeLog(console: Console; label = "".cstring) {.importcpp.}   Source   Edit
proc table(console: Console) {.importcpp, varargs.}   Source   Edit
func dir(console: Console; obj: auto) {.importcpp.}   Source   Edit
func dirxml(console: Console; obj: auto) {.importcpp.}   Source   Edit
func timeStamp(console: Console; label: cstring) {.importcpp.}

..warning:: non-standard

  Source   Edit


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.


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
  Source   Edit