UNPKG

wuchale

Version:

Protobuf-like i18n from normal code

32 lines 867 B
const colors = { red: 31, green: 32, yellow: 33, magenta: 35, cyan: 36, grey: 90, reset: 0, }; const encode = (code) => `\x1b[${code}m`; const colorFuncsEntries = Object.entries(colors).map(([col, code]) => [ col, (msg) => `${encode(code)}${msg}${encode(colors.reset)}`, ]); export const color = Object.fromEntries(colorFuncsEntries); export class Logger { #showMsgs = true; constructor(showMsgs) { this.#showMsgs = showMsgs; } #show = (message, type) => { if (!this.#showMsgs) { return; } console[type](message); }; log = (msg) => this.#show(msg, 'log'); info = (msg) => this.#show(color.cyan(msg), 'info'); warn = (msg) => this.#show(color.yellow(msg), 'warn'); error = (msg) => this.#show(color.red(msg), 'error'); } //# sourceMappingURL=log.js.map