mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 10:58:26 +00:00
Using elm-format for all files
This commit is contained in:
@ -1,24 +1,60 @@
|
||||
module Util.Size exposing (..)
|
||||
module Util.Size exposing
|
||||
( SizeUnit(..)
|
||||
, bytesReadable
|
||||
)
|
||||
|
||||
type SizeUnit = G|M|K|B
|
||||
|
||||
prettyNumber: Float -> String
|
||||
type SizeUnit
|
||||
= G
|
||||
| M
|
||||
| K
|
||||
| B
|
||||
|
||||
|
||||
prettyNumber : Float -> String
|
||||
prettyNumber n =
|
||||
let
|
||||
parts = String.split "." (String.fromFloat n)
|
||||
parts =
|
||||
String.split "." (String.fromFloat n)
|
||||
in
|
||||
case parts of
|
||||
n0 :: d :: [] -> n0 ++ "." ++ (String.left 2 d)
|
||||
_ -> String.join "." parts
|
||||
case parts of
|
||||
n0 :: d :: [] ->
|
||||
n0 ++ "." ++ String.left 2 d
|
||||
|
||||
bytesReadable: SizeUnit -> Float -> String
|
||||
_ ->
|
||||
String.join "." parts
|
||||
|
||||
|
||||
bytesReadable : SizeUnit -> Float -> String
|
||||
bytesReadable unit n =
|
||||
let
|
||||
k = n / 1024
|
||||
num = prettyNumber n
|
||||
k =
|
||||
n / 1024
|
||||
|
||||
num =
|
||||
prettyNumber n
|
||||
in
|
||||
case unit of
|
||||
G -> num ++ "G"
|
||||
M -> if k > 1 then (bytesReadable G k) else num ++ "M"
|
||||
K -> if k > 1 then (bytesReadable M k) else num ++ "K"
|
||||
B -> if k > 1 then (bytesReadable K k) else num ++ "B"
|
||||
G ->
|
||||
num ++ "G"
|
||||
|
||||
M ->
|
||||
if k > 1 then
|
||||
bytesReadable G k
|
||||
|
||||
else
|
||||
num ++ "M"
|
||||
|
||||
K ->
|
||||
if k > 1 then
|
||||
bytesReadable M k
|
||||
|
||||
else
|
||||
num ++ "K"
|
||||
|
||||
B ->
|
||||
if k > 1 then
|
||||
bytesReadable K k
|
||||
|
||||
else
|
||||
num ++ "B"
|
||||
|
Reference in New Issue
Block a user