smart-console
Simple JavaScript library that provides shorthand methods to manage console output with 0 dependencies. Customize your console output with different colors and format styles.
You can find the same library for the browser here.
For more info e images see Git Hub
Every console object method (for more info: Node.js "Console") has a name shortcut. Furthermore, predefined colors and style can be added to the log() messages.
Version 4.0
New Features:
- Code completely rewritten with ES6 syntax
- Add new "verbose" method. It is as a normal log but the output, at the beginning, has filename and number line. Any existing log method can be used in verbose mode, just use "v" instead of "l" (eg: c.l(text) becomes c.v(text) and c.lRBG(text) becomes c.vRBG(text))
- Add new console methods: clear, count and countReset. Only for node version 8.3.0 or newer
- Add TypeScript definition file
- Add default colors to error, warning and info methods
- Add a new way to insert variables in log
- Add trace method
- "process" object no longer supported
How to use it:
Insert the library as usual:
npm install --save smart-console
// JavaScript fileconst c = ; // TypeScript file;
Write 'c' instead of 'console' and use one of the method shortcuts. For example:
console; // Becomesc;
Shorthands for console methods
All the shorthand methods use lower case
c = consolec = console // node >= v8.3.0c = console // node >= v8.3.0c = console // node >= v8.3.0cdirobject optObj = consoledirc = consolec = consolec = consolec = consolec = consolec = consolec = consolec = console // to log stringify objectsc = console // NEW - to log filename and number line
For log() messages you can use 4 different ways to insert a variable:
let str = 'Awesome';c;c;c;c; // NEW
The method j() can be used to log JS and JSON objects using JSON.stringify
var jsonObj = 'pas': 'rex' 'pas1': 'rex' 'pas2': 'rex' 'pas3': 'rex';c;// output// {// 'pas': 'rex',// 'pas1': 'rex',// 'pas2': 'rex',// 'pas3': 'rex'// }var jsObj = pas: 'rex' pas1: 'rex' pas2: 'rex' pas3: 'rex';c;// output// {// 'pas': 'rex',// 'pas1': 'rex',// 'pas2': 'rex',// 'pas3': 'rex'// }
A second parameter can be added to insert white spaces. By default they are set to 4
var jsonObj = 'pas': 'rex' 'pas1': 'rex' 'pas2': 'rex' 'pas3': 'rex';c;// output// {// 'pas': 'rex',// 'pas1': 'rex',// 'pas2': 'rex',// 'pas3': 'rex'// }
The new method v() "verbose" can be used to log message with filename and line number. Any log method can be used, just use "v" instead of "l"
c becomes cc becomes cc becomes cc becomes c// output// [File: path/file_name] [Line: 150:10] Text message
Format styles for log() method, for verbose use "v" instead of "l"
Format styles use lower case
c = boldc = faintc = underlinec = blinkc = negativec = hidden
Colors for log() method, for verbose use "v" instead of "l"
Colors use upper case
c = blackc = redc = greenc = yellowc = bluec = magentac = cyanc = white
Bold + Colors for log() method, for verbose use "v" instead of "l"
Format styles use lower case and Colors use upper case
c = bold + blackc = bold + redc = bold + greenc = bold + yellowc = bold + bluec = bold + magentac = bold + cyanc = bold + white
Underline + Bold + Colors for log() method, for verbose use "v" instead of "l"
Format styles use lower case and Colors use upper case, bold style is added by default
c = underline + bold + blackc = underline + bold + redc = underline + bold + greenc = underline + bold + yellowc = underline + bold + bluec = underline + bold + magentac = underline + bold + cyanc = underline + bold + white
Blink + Bold + Colors for log() method, for verbose use "v" instead of "l"
Format styles use lower case and Colors use upper case, bold style is added by default
c = blink + bold + blackc = blink + bold + redc = blink + bold + greenc = blink + bold + yellowc = blink + bold + bluec = blink + bold + magentac = blink + bold + cyanc = blink + bold + white
Background Color + Bold for log() method, for verbose use "v" instead of "l"
Background Colors use upper case, bold style is added by default
c = background + bold + blackc = background + bold + redc = background + bold + greenc = background + bold + yellowc = background + bold + bluec = background + bold + magentac = background + bold + cyanc = background + bold + white
Different console colors produce different effects and contrasts
If you forget the shortcuts' name:
c; // console methods