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
| Method | Notes |
|---|---|
log, debug, dirxml | Print the arguments, separated by a space. debug is grey. |
info, warn, error | Same, behind ℹ, ⚠ and ✖. |
assert | Prints Assertion failed behind ✖ when the condition is falsy. A string message follows after : . |
trace | Prints Trace, the arguments and the caller's stack. |
dir | Prints one value. A string is quoted. |
table | Draws an array or object as a table. The second argument picks the columns. |
count, countReset | Count per label. default is the label when omitted. |
time, timeLog, timeEnd | Print label: 1.234ms. A missing or duplicate timer warns. |
group, groupCollapsed, groupEnd | Indent what follows. The label is marked ▼ or ▶. |
clear | Closes 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:
| Specifier | Prints |
|---|---|
%s | The argument as a string |
%d, %i | The integer at the start of the argument, or NaN |
%f | The decimal number at the start of the argument, or NaN |
%o | The argument nested up to four levels, with non-enumerable own properties in square brackets, as [length]: 3 |
%O | The argument as console.dir prints it |
%c | Takes its argument. Colors the text after it, see Differences from Node |
%% | A % |
console.log("%s is %d years", "Ann", 42.9);Ann is 42 yearsOutput
Every method writes to the host's stderr.
| Where | What happens |
|---|---|
| The development window | Shows the output in the terminal that ran inca dev |
| A packaged app | Has no readable stderr, so the output is not visible |
A line starts with a marker:
| Marker | Starts |
|---|---|
✖ | 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
Proxyprints as its target. A revokedProxyprints<Revoked Proxy>. - An array hole prints as
<1 empty item>. A run of holes counts as one entry. - An array, typed array,
MaporSetprints 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:
| Variable | Effect |
|---|---|
NO_COLOR | A non-empty value turns color off. It wins over FORCE_COLOR. |
FORCE_COLOR | 0 or false turns color off. Any other non-empty value turns it on. An empty value is ignored. |
Differences from Node
%dand%iparse an integer where Node converts the whole value to a number.%sprints an object's string form where Node inspects it.%capplies thecolordeclaration 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 areblack,red,green,yellow,blue,magenta,cyan,white,grayandgrey, 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%sand a conversion that throws, which print asconsole.dirdoes.console.debugignores it.
Known issues
- Output is not wrapped across lines.
- A node prints as its interface and its own properties, such as
HTMLElement {}orText {}. These nodes show one property:- an
inputitsvalue - a
templateitscontent
- an
- An SVG or MathML element prints as
Element. windowprints asEventTargetwith its handler properties, such asonclick.- An event prints as its class with only
isTrusted, such asPointerEvent { 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
WeakMapprints as a plain object. A circular reference prints[Object]at the depth limit, with no marker. %oprints no hidden fields of a typed array, such as[buffer].- A
Date,RegExp,Map,Set,URLorURLSearchParamsleaves out the properties added to it and the name of a subclass. - A
URLand aURLSearchParamspast the depth limit print as[URL]and[URLSearchParams], and aURLSearchParamsprints at most 100 pairs. - A string inside an array or object is always single-quoted.
- Timers always print milliseconds.