UNPKG

poku

Version:

🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.

78 lines (77 loc) 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLargestStringLength = exports.format = exports.Formatter = exports.backgroundColor = void 0; exports.backgroundColor = { white: 7, black: 40, grey: 100, red: 41, green: 42, yellow: 43, blue: 44, magenta: 45, cyan: 46, brightRed: 101, brightGreen: 102, brightYellow: 103, brightBlue: 104, brightMagenta: 105, brightCyan: 106, }; const ESC = '\x1b['; class Formatter { constructor(text) { this.parts = ''; this.text = text; } code(code) { this.parts += `${ESC}${code}m`; return this; } static create(text) { return new Formatter(text); } counter(current, total, pad = '0') { const totalDigits = String(total).length; this.parts += String(current).padStart(totalDigits, pad); return this; } dim() { return this.code('2'); } bold() { return this.code('1'); } underline() { return this.code('4'); } info() { return this.code('94'); } italic() { return this.code('3'); } success() { return this.code('32'); } fail() { return this.code('91'); } gray() { return this.code('90'); } cyan() { return this.code('96'); } bg(color) { return this.code(String(exports.backgroundColor[color])).bold(); } [Symbol.toPrimitive]() { return `${this.parts}${this.text}${ESC}0m`; } } exports.Formatter = Formatter; const format = (text) => Formatter.create(text); exports.format = format; const getLargestStringLength = (arr) => arr.reduce((max, current) => Math.max(max, current.length), 0); exports.getLargestStringLength = getLargestStringLength;