MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / formatBytes

Function formatBytes

src/pkg/utils/utils.ts:497–506  ·  view source on GitHub ↗
(bytes: number, decimals: number = 2)

Source from the content-addressed store, hash-verified

495 * @returns 格式化的字符串,例如 "1.23 MB"
496 */
497export const formatBytes = (bytes: number, decimals: number = 2): string => {
498 if (bytes === 0) return "0 B";
499
500 const k = 1024;
501 const units = ["B", "KB", "MB", "GB", "TB"];
502 const i = Math.floor(Math.log(bytes) / Math.log(k));
503 const value = bytes / Math.pow(k, i);
504
505 return `${value.toFixed(decimals)} ${units[i]}`;
506};
507
508// TM Xhr Header 兼容处理,原生xhr \r\n 在尾,但TM的GMXhr没有;同时除去冒号后面的空白
509export const normalizeResponseHeaders = (headersString: string) => {

Callers 2

fetchValidScriptFunction · 0.90
utils.test.tsFile · 0.90

Calls 1

logMethod · 0.80

Tested by

no test coverage detected