solve any problem (#248)

This commit is contained in:
tmshv authored and GitHub committed 2026-02-08 12:22:52 +07:00
1 parent 6da5a7a07b
commit 562b4f6408
9 files changed
+27 -16

No files matched your search

+1
View File
@@ -26,6 +26,7 @@ describe("size", () => {
it("should return empty string for non-finite values", () => {
expect(size(Infinity)).toBe("")
expect(size(-Infinity)).toBe("")
})
it("should format bytes", () => {
+2 -2
View File
@@ -14,8 +14,8 @@ export function ext(mimeType: string): string {
return mimeType
}
export function size(bytes: any, precision = 1): string {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return ""
export function size(bytes: number, precision = 1): string {
if (Number.isNaN(bytes) || !Number.isFinite(bytes)) return ""
const number = Math.floor(Math.log(bytes) / Math.log(1024))
const size = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision)