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

  1. import std/jsconsole
  2. console.log "%c My Debug Message", "color: red" # Notice the "%c"
  3. console.log "%c My Debug %c Message", "color: red", "font-size: 2em"

Imports

since, miscdollars

Types

  1. Console = ref object of JsRoot

Source Edit

Vars

  1. console {.importc, nodecl.}: Console

Source Edit

Procs

  1. proc clear(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
  2. forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/clear Source Edit

  1. proc count(console: Console; label = "".cstring) {.importcpp, ...raises: [],
  2. tags: [], forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/count Source Edit

  1. proc countReset(console: Console; label = "".cstring) {.importcpp, ...raises: [],
  2. tags: [], forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/countReset Source Edit

  1. proc debug(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
  2. forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/debug Source Edit

  1. func dir(console: Console; obj: auto) {.importcpp, ...raises: [], tags: [],
  2. forbids: [].}

https://developer.mozilla.org/en-US/docs/Web/API/Console/dir Source Edit

  1. func dirxml(console: Console; obj: auto) {.importcpp, ...raises: [], tags: [],
  2. forbids: [].}

https://developer.mozilla.org/en-US/docs/Web/API/Console/dirxml Source Edit

  1. proc error(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
  2. forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/error Source Edit

  1. proc group(console: Console; label = "".cstring) {.importcpp, ...raises: [],
  2. tags: [], forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/group Source Edit

  1. proc groupCollapsed(console: Console; label = "".cstring) {.importcpp,
  2. ...raises: [], tags: [], forbids: [].}

https://developer.mozilla.org/en-US/docs/Web/API/Console/groupCollapsed Source Edit

  1. proc groupEnd(console: Console) {.importcpp, ...raises: [], tags: [], forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/groupEnd Source Edit

  1. proc info(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
  2. forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/info Source Edit

  1. proc log(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
  2. forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/log Source Edit

  1. proc table(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
  2. forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/table Source Edit

  1. proc time(console: Console; label = "".cstring) {.importcpp, ...raises: [],
  2. tags: [], forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/time Source Edit

  1. proc timeEnd(console: Console; label = "".cstring) {.importcpp, ...raises: [],
  2. tags: [], forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/timeEnd Source Edit

  1. proc timeLog(console: Console; label = "".cstring) {.importcpp, ...raises: [],
  2. tags: [], forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/timeLog Source Edit

  1. func timeStamp(console: Console; label: cstring) {.importcpp, ...raises: [],
  2. tags: [], forbids: [].}

https://developer.mozilla.org/en-US/docs/Web/API/Console/timeStamp

..warning:: non-standard

Source Edit

  1. proc trace(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
  2. forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/trace Source Edit

  1. proc warn(console: Console) {.importcpp, varargs, ...raises: [], tags: [],
  2. forbids: [].}

https://developer.mozilla.org/docs/Web/API/Console/warn Source Edit

Templates

  1. template exception(console: Console; args: varargs[untyped])

Alias for console.error(). Source Edit

  1. 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:

  1. console.jsAssert(42 == 42) # OK
  2. console.jsAssert(42 != 42) # Fail, prints "Assertion failed" and continues
  3. console.jsAssert('`' == '\n' and '\t' == '\0') # Message correctly formatted
  4. assert 42 == 42 # Normal assertions keep working

Source Edit