UNPKG

oj

Version:

A unified templating language for the people. Thirsty people.

1 lines 1.48 kB
function Console(e,t){if(!(this instanceof Console))return new Console(e,t);if(!e||!util.isFunction(e.write))throw new TypeError("Console expects a writable stream instance");t||(t=e);var n={writable:!0,enumerable:!1,configurable:!0};n.value=e,Object.defineProperty(this,"_stdout",n),n.value=t,Object.defineProperty(this,"_stderr",n),n.value={},Object.defineProperty(this,"_times",n),Object.keys(Console.prototype).forEach(function(e){this[e]=this[e].bind(this)},this)}var util=require("util");Console.prototype.log=function(){this._stdout.write(util.format.apply(this,arguments)+"\n")},Console.prototype.info=Console.prototype.log,Console.prototype.warn=function(){this._stderr.write(util.format.apply(this,arguments)+"\n")},Console.prototype.error=Console.prototype.warn,Console.prototype.dir=function(e){this._stdout.write(util.inspect(e,{customInspect:!1})+"\n")},Console.prototype.time=function(e){this._times[e]=Date.now()},Console.prototype.timeEnd=function(e){var t=this._times[e];if(!t)throw new Error("No such label: "+e);var n=Date.now()-t;this.log("%s: %dms",e,n)},Console.prototype.trace=function(){var e=new Error;e.name="Trace",e.message=util.format.apply(this,arguments),Error.captureStackTrace(e,arguments.callee),this.error(e.stack)},Console.prototype.assert=function(e){if(!e){var t=Array.prototype.slice.call(arguments,1);require("assert").ok(!1,util.format.apply(this,t))}},module.exports=new Console(process.stdout,process.stderr),module.exports.Console=Console