diy-log
Version:
Various console log level prefixes with support for color symbols and tags.
118 lines (116 loc) • 5.23 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// index.ts
var diy_log_exports = {};
__export(diy_log_exports, {
colors: () => import_picocolors.default,
default: () => diy_log_default,
done: () => done,
error: () => error,
info: () => info,
log: () => log,
success: () => done,
symbols: () => symbols,
tag: () => tag,
time: () => time,
timestamp: () => import_time_stamp.default,
warn: () => warn
});
module.exports = __toCommonJS(diy_log_exports);
var import_picocolors = __toESM(require("picocolors"));
var import_time_stamp = __toESM(require("time-stamp"));
function isUnicodeSupported() {
if (process.platform !== "win32") {
return process.env.TERM !== "linux";
}
return Boolean(process.env.CI) || Boolean(process.env.WT_SESSION) || // Windows Terminal
Boolean(process.env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)
process.env.ConEmuTask === "{cmd::Cmder}" || // ConEmu and cmder
process.env.TERM_PROGRAM === "Terminus-Sublime" || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty" || process.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
}
var symbols = function() {
const main = {
info: import_picocolors.default.blue("\u2139"),
done: import_picocolors.default.green("\u2714"),
success: import_picocolors.default.green("\u2714"),
warn: import_picocolors.default.yellow("\u26A0"),
error: import_picocolors.default.red("\u2716")
};
const fallbacks = {
info: import_picocolors.default.blue("i"),
done: import_picocolors.default.green("\u221A"),
success: import_picocolors.default.green("\u221A"),
warn: import_picocolors.default.yellow("\u203C"),
error: import_picocolors.default.red("\xD7")
};
return isUnicodeSupported() ? main : fallbacks;
}();
function logFn(fn, args, prefix) {
if (prefix) {
process.stdout.write(prefix + " ");
}
fn.apply(console, args);
}
var log = (...args) => logFn(console.log, args);
var time = (...args) => {
const times = (0, import_time_stamp.default)("HH:mm:ss");
logFn(console.log, args, "[" + import_picocolors.default.gray(times) + "]");
};
var info = (...args) => logFn(console.info, args, symbols.info);
var error = (...args) => logFn(console.error, args, symbols.error);
var done = (...args) => logFn(console.log, args, symbols.done);
var warn = (...args) => logFn(console.warn, args, symbols.warn);
function tagFn(message, label, fn, bgColorFn, colorFn) {
const labelStr = bgColorFn.call(import_picocolors.default, import_picocolors.default.black(` ${label} `));
fn.call(console, labelStr, typeof colorFn === "function" ? colorFn.call(import_picocolors.default, message) : message);
}
var tag = (message, type = "info", label) => {
var _a;
label = label != null ? label : type.toLocaleUpperCase();
return (_a = tag[type]) == null ? void 0 : _a.call(void 0, message, label);
};
tag.info = (message, label) => tagFn(message, label ? label : "info".toLocaleUpperCase(), console.info, import_picocolors.default.bgBlue);
tag.done = tag.success = (message, label) => tagFn(message, label ? label : "done".toLocaleUpperCase(), console.log, import_picocolors.default.bgGreen);
tag.warn = (message, label) => tagFn(message, label ? label : "warn".toLocaleUpperCase(), console.warn, import_picocolors.default.bgYellow, import_picocolors.default.yellow);
tag.error = (message, label) => tagFn(message, label ? label : "error".toLocaleUpperCase(), console.error, import_picocolors.default.bgRed, import_picocolors.default.red);
var diy_log_default = { log, time, info, error, done, warn, symbols, colors: import_picocolors.default, tag, timestamp: import_time_stamp.default };
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
colors,
done,
error,
info,
log,
success,
symbols,
tag,
time,
timestamp,
warn
});