util-ex
Version:
Browser-friendly enhanced util fully compatible with standard node.js
40 lines (36 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.log = log;
var _format = _interopRequireDefault(require("./format.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function pad(n) {
return n < 10 ? `0${n.toString(10)}` : n.toString(10);
}
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
// 26 Feb 16:19:34
function timestamp() {
const d = new Date();
const time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':');
return [d.getDate(), months[d.getMonth()], time].join(' ');
}
/**
* Logs a message to the console with a timestamp prefix.
*
* @param {...any} args - The arguments to log to the console.
*/
function log() {
// eslint-disable-next-line no-console
console.log('%s - %s', timestamp(), _format.default.apply(exports, arguments));
}
;
/*
module.exports = function(msg, type, depth) {
if (isNaN(depth)) depth = 10;
if (!type) type = 'log';
console[type](inspect(msg, {depth: depth}));
}
*/
var _default = exports.default = log;