memory-watch
Version:
Advanced Node.js memory monitoring with stack trace analysis, user code detection, and memory leak identification
23 lines • 722 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatBytes = formatBytes;
exports.getMemoryPercentage = getMemoryPercentage;
/**
* Format bytes to human readable format
*/
function formatBytes(bytes, decimals = 2) {
if (bytes === 0)
return "0 Bytes";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
}
/**
* Get memory usage percentage
*/
function getMemoryPercentage(used, total) {
return total > 0 ? used / total : 0;
}
//# sourceMappingURL=formatBytes.js.map
;