console-ansi
Easy console coloring and prefixing via Proxy object with ANSI strings. Works in Node.js and in browsers that support ANSI strings.
Installation
npm install console-ansi
Usage
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
-
ConsoleAnsi :
object
-
ConsoleAnsiThemeAttributeArray :
Array.<number>
-
Array for ANSI definition [start, end].
-
ConsoleAnsiTheme :
Object.<string, ConsoleAnsiThemeAttributeArray>
|Object.<string, Array.<ConsoleAnsiThemeAttributeArray>>
-
Theme object consisting of ANSI styles or Array of ANSI styles.
-
ConsoleAnsiLevel :
string
-
Current log level. Can be any console method but levels property only defines log(1)/info(2)/warn(3)/error(4).
-
ConsoleAnsiLevels :
Object.<ConsoleAnsiLevel, number>
-
Levels object consisting of console method as keys and numbered priority.
-
ConsoleAnsiSymbol :
Object.<string, string>
-
Map of unicode symbols to be prepended to certain console methods.
console-ansi
ConsoleAnsiTheme
console-ansi.styles : Basic ANSI escape codes map
Kind: static property of console-ansi
See
ConsoleAnsi
console-ansi.default : Export a Proxy object to automatically style the console with ANSI strings.
Kind: static property of console-ansi
ConsoleAnsi
console-ansi.getConsole(options) ⇒ Get an instance of the Proxy-ed console. Useful if you need different prefixes for instance.
Kind: static method of console-ansi
Param | Type |
---|---|
options | ConsoleAnsi |
object
ConsoleAnsi : Kind: global typedef Properties
Name | Type | Default | Description |
---|---|---|---|
[prefix] | string |
"""" |
A string to prepend to every log. |
[theme] | ConsoleAnsiTheme |
Color definition associated to console methods. | |
[level] | ConsoleAnsiLevel |
"log" |
A minimum log level value. See ConsoleAnsiLevels. |
[levels] | ConsoleAnsiLevels |
{ error: 5, warn: 4, info: 3, log: 2 } |
Numbered priority associated to console methods to match above for level property. |
[symbol] | ConsoleAnsiSymbol |
{ log: "✔", info: "ℹ", warn: "⚠", error: "✖" } |
Unicode symbols to prepend to defined console methods. |
[noColor] | boolean |
false |
Disable color ansi sequence. |
Array.<number>
ConsoleAnsiThemeAttributeArray : Array for ANSI definition [start, end].
Object.<string, ConsoleAnsiThemeAttributeArray>
| Object.<string, Array.<ConsoleAnsiThemeAttributeArray>>
ConsoleAnsiTheme : Theme object consisting of ANSI styles or Array of ANSI styles.
string
ConsoleAnsiLevel : Current log level. Can be any console method but levels property only defines log(1)/info(2)/warn(3)/error(4).
Object.<ConsoleAnsiLevel, number>
ConsoleAnsiLevels : Levels object consisting of console method as keys and numbered priority.
Object.<string, string>
ConsoleAnsiSymbol : Map of unicode symbols to be prepended to certain console methods.
Kind: global typedef
License
MIT. See license file.