UNPKG

maxmin

Version:

Get a pretty output of the original, minified, gzipped size of a string or buffer: 130 B → 91 B → 53 B (gzip)

21 lines (15 loc) 636 B
import gzipSize from 'gzip-size'; import prettyBytes from 'pretty-bytes'; import chalk from 'chalk'; import figures from 'figures'; const arrow = ' ' + figures.arrowRight + ' '; const format = size => chalk.green(prettyBytes(size)); export default function maxmin(max, min, useGzip = false) { const maxString = format(typeof max === 'number' ? max : max.length); const minString = format(typeof min === 'number' ? min : min.length); let returnValue = maxString + arrow + minString; if (useGzip && typeof min !== 'number') { returnValue += arrow + format(gzipSize.sync(min)) + chalk.gray(' (gzip)'); } return returnValue; }