MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / byteToString

Function byteToString

frontend/packages/common/src/utils/postcat.tsx:57–85  ·  view source on GitHub ↗
(inputByteLength: number)

Source from the content-addressed store, hash-verified

55}
56
57export function byteToString(inputByteLength: number): string {
58 inputByteLength = inputByteLength || 0
59
60 // Define thresholds for byte units
61 const KB = 1024
62 const MB = 1024 * KB
63 const GB = 1024 * MB
64
65 // Helper function to format the byte length into a string
66 const formatSize = (size: number, unit: string) => {
67 const formattedSize = size.toFixed(2)
68 // Remove unnecessary '.00'
69 if (formattedSize.endsWith('.00')) {
70 return `${parseInt(formattedSize, 10)} ${unit}`
71 }
72 return `${formattedSize} ${unit}`
73 }
74
75 // Convert and format byte length to appropriate unit
76 if (inputByteLength < 0.1 * KB) {
77 return formatSize(inputByteLength, 'B')
78 } else if (inputByteLength < 0.1 * MB) {
79 return formatSize(inputByteLength / KB, 'KB')
80 } else if (inputByteLength < 0.1 * GB) {
81 return formatSize(inputByteLength / MB, 'MB')
82 } else {
83 return formatSize(inputByteLength / GB, 'GB')
84 }
85}
86
87export function determineCheckState<T extends { isRequired: 0 | 1 | boolean }>(items: T[]): CheckedStatus {
88 let allChecked = true

Callers 1

ResponseIndicatorFunction · 0.90

Calls 1

formatSizeFunction · 0.85

Tested by

no test coverage detected