console-extras
v1.0.0
Published
A slightly upgraded console.log/warn/info etc.
Downloads
8
Readme
Improved console
A slightly upgraded console. Methods are pre-bound to the correct this
, can be chained and support partial application. Output can be turned on and off by using enable()
and disable()
. You can either replace (or rather shadow) the global console or create your own.
The methods are created from the original console, so this library supports whatever the console in your browser or node version supports.
import
console, // Replacement for the global console
{ Console } // Constructor function for DIY console instances
from "console-extras";
// Method calls can be chained
console
.groupCollapsed("Hello World")
.info(0)
.log([ 1, 2, 3 ])
.groupEnd();
// Methods are bound by default
Promise.resolve(42).then(console.log);
// Partial application
setTimeout(console.count.partial("A")); // A: 1
setTimeout(console.count.partial("A")); // A: 2
// Create your own console
const myConsole = new Console();
let x = myConsole
.disable()
.log(23) // skipped
.enable()
.log(42); // logged