UNPKG

silvie

Version:

Typescript Back-end Framework

126 lines (125 loc) 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } const colors = { none: '\x1b[0m', bright: '\x1b[1m', dim: '\x1b[2m', underscore: '\x1b[4m', blink: '\x1b[5m', reverse: '\x1b[7m', hidden: '\x1b[8m', fg_black: '\x1b[30m', fg_red: '\x1b[31m', fg_green: '\x1b[32m', fg_yellow: '\x1b[33m', fg_blue: '\x1b[34m', fg_magenta: '\x1b[35m', fg_cyan: '\x1b[36m', fg_white: '\x1b[37m', bg_black: '\x1b[40m', bg_red: '\x1b[41m', bg_green: '\x1b[42m', bg_yellow: '\x1b[43m', bg_blue: '\x1b[44m', bg_magenta: '\x1b[45m', bg_cyan: '\x1b[46m', bg_white: '\x1b[47m' }; class LogString { constructor(str) { _defineProperty(this, "str", void 0); _defineProperty(this, "options", void 0); this.str = str || ''; this.reset(); } color(colorName) { this.options.color = colorName; return this; } defaultColor() { this.options.color = undefined; return this; } background(colorName) { this.options.background = colorName; return this; } defaultBackground() { this.options.background = undefined; return this; } bright(state = true) { this.options.bright = state; return this; } dim(state = true) { this.options.dim = state; return this; } underscore(state = true) { this.options.underscore = state; return this; } blink(state = true) { this.options.blink = state; return this; } reverse(state = true) { this.options.reverse = state; return this; } hidden(state = true) { this.options.hidden = state; return this; } reset() { this.options = { bright: false, dim: false, underscore: false, blink: false, reverse: false, hidden: false, background: undefined, color: undefined }; return this; } getText() { let output = ''; if (this.options.bright) { output += colors.bright; } if (this.options.dim) { output += colors.dim; } if (this.options.underscore) { output += colors.underscore; } if (this.options.blink) { output += colors.blink; } if (this.options.reverse) { output += colors.reverse; } if (this.options.hidden) { output += colors.hidden; } if (this.options.background) { output += colors[`bg_${this.options.background}`]; } if (this.options.color) { output += colors[`fg_${this.options.color}`]; } output += this.str; output += colors.none; return output; } } exports.default = LogString;