Skip to content

Console unreleased ​

Incarnative.js provides a built-in console object. It is available in your app without an import.

The console object follows the WHATWG Console Standard. Where the standard leaves the format open, such as how values print, the host follows Node's util.inspect.

Methods ​

MethodNotes
log, debug, dirxmlPrint the arguments, separated by a space. debug is grey.
info, warn, errorSame, behind ℹ, ⚠ and ✖.
assertPrints Assertion failed behind ✖ when the condition is falsy. A string message follows after : .
tracePrints Trace, the arguments and the caller's stack.
dirPrints one value. A string is quoted.
tableDraws an array or object as a table. The second argument picks the columns.
count, countResetCount per label. default is the label when omitted.
time, timeLog, timeEndPrint label: 1.234ms. A missing or duplicate timer warns.
group, groupCollapsed, groupEndIndent what follows. The label is marked ▼ or ▶.
clearCloses every open group.

profile, profileEnd and timeStamp are not provided.

Format specifiers ​

When the first argument is a string and more arguments follow, these specifiers take the next argument:

SpecifierPrints
%sThe argument as a string
%d, %iThe integer at the start of the argument, or NaN
%fThe decimal number at the start of the argument, or NaN
%o, %OThe argument as console.dir prints it
%cNothing. Takes its argument
%%A %
js
console.log("%s is %d years", "Ann", 42.9);
Ann is 42 years

Output ​

Every method writes to the host's stderr.

WhereWhat happens
The development windowShows the output in the terminal that ran inca dev
A packaged appHas no readable stderr, so the output is not visible

A line starts with a marker:

MarkerStarts
✖An error line or a failed assert
⚠A warn line, or a warning from a counter or timer
ℹAn info line
│ Every line inside an open group, once per level

Colour ​

Output is coloured when stderr is a terminal, and values are coloured by type as in Node. These environment variables override the terminal check:

VariableEffect
NO_COLORA non-empty value turns colour off. It wins over FORCE_COLOR.
FORCE_COLOR0 or false turns colour off. Any other non-empty value turns it on. An empty value is ignored.

Differences from Node ​

  • %d and %i parse an integer where Node converts the whole value to a number. %s prints an object's string form where Node inspects it.

Known issues ​

  • Output is not wrapped across lines and is not cut after 100 items.
  • A property getter runs when its object is printed.
  • A class instance prints without its class name. Symbol-keyed properties and extra properties on arrays and errors are dropped. A Promise, a typed array and a WeakMap print as plain objects. A circular reference prints [Object] at the depth limit, with no marker.
  • A Date, RegExp, Map or Set prints like Node, but properties added to it and the name of a subclass are left out.
  • A string inside an array or object is always single-quoted.
  • %o and %O print alike, and %c drops its styling.
  • Timers always print milliseconds.

Released under the MIT or Apache-2.0 license.