feat: add components

This commit is contained in:
2025-04-04 17:19:07 +08:00
parent 6f494ec9ca
commit c37b9f0ab2
40 changed files with 2088 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
var UNITS = ['bytes', 'KB', 'MB', 'GB', 'TB'];
var UNITS_BYTES = [0, Math.pow(1024, 1), Math.pow(1024, 2), Math.pow(1024, 3), Math.pow(1024, 4)];
exports.showBytes = (bytes) => {
for (var i = 0; i < (UNITS.length - 1); i++) {
if ((bytes >= UNITS_BYTES[i]) && bytes < UNITS_BYTES[i + 1]) {
if (i == 0) {
return bytes + ((bytes <= 1) ? ' byte' : ' bytes');
} else {
return (parseInt(bytes * 100 / UNITS_BYTES[i]) / 100) + ' ' + UNITS[i];
}
}
}
return (parseInt(bytes * 100 / UNITS_BYTES[i]) / 100) + ' ' + UNITS[i]; // i == UNITS.length - 1
};