Files
rspade_system/node_modules/webpack/lib/SizeFormatHelpers.js
root 3ce82a924a Add JS-CATCH-FALLBACK-01 rule and update npm packages
Add PHP-ALIAS-01 rule: prohibit field aliasing in serialization

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-23 07:36:18 +00:00

26 lines
587 B
JavaScript
Executable File

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Sean Larkin @thelarkinn
*/
"use strict";
/**
* @param {number=} size the size in bytes
* @returns {string} the formatted size
*/
module.exports.formatSize = (size) => {
if (typeof size !== "number" || Number.isNaN(size) === true) {
return "unknown size";
}
if (size <= 0) {
return "0 bytes";
}
const abbreviations = ["bytes", "KiB", "MiB", "GiB"];
const index = Math.floor(Math.log(size) / Math.log(1024));
return `${Number((size / 1024 ** index).toPrecision(3))} ${abbreviations[index]}`;
};