Skip to content

Console ​

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
%oThe argument nested up to four levels, with non-enumerable own properties in square brackets, as [length]: 3
%OThe argument as console.dir prints it
%cTakes its argument. Colors the text after it, see Differences from Node
%%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

Printed values ​

  • An object's own accessor property prints as [Getter], [Setter] or [Getter/Setter]. Printing reads only the kind of the accessor.
  • A Proxy prints as its target. A revoked Proxy prints <Revoked Proxy>.
  • An array hole prints as <1 empty item>. A run of holes counts as one entry.
  • An array, typed array, Map or Set prints its first 100 entries, then ... N more items.
  • A key that is not a plain identifier is quoted.

A label for count, countReset, time, timeLog or timeEnd is converted to a string. Converting a Proxy label can run the code in its handlers. An absent label, an undefined label and a label that fails to convert become default.

Color ​

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

VariableEffect
NO_COLORA non-empty value turns color off. It wins over FORCE_COLOR.
FORCE_COLOR0 or false turns color 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.
  • %c applies the color declaration of its argument to the text after it, up to the next %c, when color is on. With color off it prints nothing. The values are black, red, green, yellow, blue, magenta, cyan, white, gray and grey, optionally followed by !important. Hex, rgb(), hsl() and every other property are ignored, and an argument with no usable color ends the span. Arguments after the format string keep their own colors, as do %o, %O, a Symbol under %s and a conversion that throws, which print as console.dir does. console.debug ignores it.

Known issues ​

  • Output is not wrapped across lines.
  • A node prints as its interface and its own properties, such as HTMLElement {} or Text {}. These nodes show one property:
    • an input its value
    • a template its content
  • An SVG or MathML element prints as Element.
  • window prints as EventTarget with its handler properties, such as onclick.
  • An event prints as its class with only isTrusted, such as PointerEvent { isTrusted: [Getter] } for a click. Its other fields are getters on its prototype.
  • Symbol-keyed properties and extra properties on arrays, typed arrays and errors are dropped. A WeakMap prints as a plain object. A circular reference prints [Object] at the depth limit, with no marker.
  • %o prints no hidden fields of a typed array, such as [buffer].
  • A Date, RegExp, Map, Set, URL or URLSearchParams leaves out the properties added to it and the name of a subclass.
  • A URL and a URLSearchParams past the depth limit print as [URL] and [URLSearchParams], and a URLSearchParams prints at most 100 pairs.
  • A string inside an array or object is always single-quoted.
  • Timers always print milliseconds.

Released under the MIT or Apache-2.0 license.