tinify-client
Version:
A CLI to compress your images not only intelligently but also to the EXTREME!
19 lines (18 loc) • 638 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toReadableSize = exports.getPercentageOff = void 0;
function getPercentageOff(before, after) {
const diff = before - after;
return (before !== 0 ? (diff / before * 100).toFixed(2) : '0') + '%';
}
exports.getPercentageOff = getPercentageOff;
function toReadableSize(sizeInByte) {
if (sizeInByte >= 1024 * 1024) {
return (sizeInByte / 1024 / 1024).toFixed(2) + 'MB';
}
if (sizeInByte >= 1024) {
return (sizeInByte / 1024).toFixed(2) + 'KB';
}
return sizeInByte + 'B';
}
exports.toReadableSize = toReadableSize;