solve any problem (#248)
This commit is contained in:
1 parent
6da5a7a07b
commit
562b4f6408
9 files changed
+27
-16
No files matched your search
@@ -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
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user