humanifyjs
Version:
> Deobfuscate Javascript code using LLMs ("AI")
38 lines (37 loc) • 1.19 kB
JavaScript
import { verbose } from "./verbose.js";
export function showProgress(stream) {
let bytes = 0;
let i = 0;
stream.on("data", (data) => {
var _a, _b;
bytes += data.length;
if (i++ % 1000 !== 0)
return;
(_b = (_a = process.stdout).clearLine) === null || _b === void 0 ? void 0 : _b.call(_a, 0);
process.stdout.write(`\rDownloaded ${formatBytes(bytes)}`);
});
}
function formatBytes(numBytes) {
const units = ["B", "KB", "MB", "GB", "TB"];
let unitIndex = 0;
while (numBytes > 1024 && unitIndex < units.length) {
numBytes /= 1024;
unitIndex++;
}
return `${numBytes.toFixed(2)} ${units[unitIndex]}`;
}
export function showPercentage(percentage) {
var _a, _b;
const percentageStr = Math.round(percentage * 100);
if (!verbose.enabled) {
(_b = (_a = process.stdout).clearLine) === null || _b === void 0 ? void 0 : _b.call(_a, 0);
process.stdout.cursorTo(0);
process.stdout.write(`Processing: ${percentageStr}%`);
}
else {
verbose.log(`Processing: ${percentageStr}%`);
}
if (percentage === 1) {
process.stdout.write("\n");
}
}