console-ansi
v3.0.1
Published
Easy console coloring and prefixing via Proxy object with ANSI strings in Node.js and CSS in browsers.
Maintainers
Readme
console-ansi
Easy console coloring and prefixing via Proxy object with ANSI strings in Node.js and CSS in browsers.

Installation
npm install console-ansiUsage
import console, { styles } from "console-ansi";
// Set prefix
console.prefix = "[test]";
// Call the console object methods as usual
console.time("Test time");
console.log("Test log");
console.info("Test info");
console.warn("Test warn");
console.error("Test error");
console.timeEnd("Test time");
// Customise color
console.theme.log = styles.blue;
console.log("Test log blue");
// Remove symbols
console.symbol = {};API
Modules
Typedefs
console-ansi
console-ansi.styles : ConsoleAnsiTheme
Basic ANSI escape codes map
Kind: static property of console-ansi See
console-ansi.palettes : ConsoleAnsiPalettes
Chrome DevTools ANSI color palettes used for CSS styling in browsers
Kind: static property of console-ansi See: Chrome DevTools
console-ansi.default : ConsoleAnsi
Export a Proxy object to automatically style the console with ANSI strings in Node.js and CSS in browsers.
Kind: static property of console-ansi
console-ansi.getConsole([options]) ⇒ ConsoleAnsi
Get an instance of the Proxy-ed console. Useful if you need different prefixes for instance.
Kind: static method of console-ansi
| Param | Type | Default | | --------- | ---------------------------------------- | --------------- | | [options] | ConsoleAnsi | {} |
ConsoleAnsi : object
Labelled methods (count/countReset, time/timeLog/timeEnd) use the
count and time theme and symbol. Their styled output is the native label
key: keep prefix, theme, symbol and noColor unchanged between related
calls.
Kind: global typedef Properties
| Name | Type | Default | Description |
| ------------ | ---------------------------------------------------- | ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [prefix] | string | """" | A string to prepend to every log. Part of the format string: avoid %. |
| [theme] | ConsoleAnsiTheme | | Color definition associated to console methods, applied to symbol, prefix and first string argument. Merged with defaults. |
| [level] | ConsoleAnsiLevel | "debug" | A minimum log level value. See ConsoleAnsiLevels. |
| [levels] | ConsoleAnsiLevels | { error: 5, warn: 4, info: 3, log: 2, debug: 1, trace: 1 } | Numbered priority associated to console methods to match above for level property. Merged with defaults. |
| [symbol] | ConsoleAnsiSymbol | | Unicode symbols to prepend to defined console methods. Merged with defaults. Defaults to a symbol per method, see source. |
| [timestamps] | boolean | false | Prepend local time to non-labelled methods, styled with theme.timestamps. |
| [noColor] | boolean | false | Disable color. |
ConsoleAnsiThemeAttribute : number | string
ANSI code or CSS declaration.
Kind: global typedef
ConsoleAnsiThemeAttributeArray : Array.<ConsoleAnsiThemeAttribute>
Array for ANSI definition [start, end] and optional CSS declaration for browsers.
Kind: global typedef
ConsoleAnsiTheme : Object.<string, ConsoleAnsiThemeAttributeArray> | Object.<string, Array.<ConsoleAnsiThemeAttributeArray>>
Theme object consisting of ANSI styles or Array of ANSI styles.
Kind: global typedef
ConsoleAnsiLevel : string
Current log level. Methods missing from levels are always shown.
Kind: global typedef
ConsoleAnsiLevels : Object.<ConsoleAnsiLevel, number>
Levels object consisting of console method as keys and numbered priority.
Kind: global typedef
ConsoleAnsiSymbol : Object.<string, string>
Map of unicode symbols to be prepended to certain console methods.
Kind: global typedef
ConsoleAnsiPalette : Object.<string, string>
Map of color names to CSS colors.
Kind: global typedef
ConsoleAnsiPalettes : object
Kind: global typedef Properties
| Name | Type | Description | | ----- | ------------------------------------------------------ | -------------------- | | light | ConsoleAnsiPalette | Light theme palette. | | dark | ConsoleAnsiPalette | Dark theme palette. |
License
MIT. See license file.
