diff options
author | Joris | 2021-05-29 19:24:41 +0200 |
---|---|---|
committer | Joris | 2021-05-29 19:24:41 +0200 |
commit | d48cafebb277e4ad4b31e883cbe4f55eef9ea4a4 (patch) | |
tree | 7f04fb49defa5fbc7984b0eee60bb7ce16a37ae2 /src/Format.purs | |
parent | 4e3cd92a8063a70dab9ae0ccafd0552c78c6e005 (diff) |
Rewrite in TypeScript
Diffstat (limited to 'src/Format.purs')
-rw-r--r-- | src/Format.purs | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/src/Format.purs b/src/Format.purs deleted file mode 100644 index e8ab661..0000000 --- a/src/Format.purs +++ /dev/null @@ -1,70 +0,0 @@ -module Format - ( number - , string - , unaccent - ) where - -import Data.Array (replicate) -import Data.Int (toNumber, fromNumber) -import Data.Maybe (fromMaybe) -import Data.String (length, joinWith, fromCharArray, toCharArray, toLower) -import Math (round, trunc, pow) -import Prelude - -number :: Int -> Number -> String -number decimalLength num = formattedIntegerPart <> formattedDecimalPart - where - formattedIntegerPart = - (if decimalLength > 0 then trunc num else round num) - # fromNumber - # fromMaybe 0 - # show - - formattedDecimalPart = - if decimalLength > 0 then - ((num - trunc num) * pow 10.0 (toNumber decimalLength)) - # round - # fromNumber - # fromMaybe 0 - # show - # \str -> "," <> (joinWith "" $ replicate (decimalLength - length str) "0") <> str - else - "" - -string :: String -> String -string = unaccent <<< toLower - -unaccent :: String -> String -unaccent = fromCharArray <<< map unaccentChar <<< toCharArray - where - unaccentChar :: Char -> Char - unaccentChar c = case c of - 'à' -> 'a' - 'á' -> 'a' - 'â' -> 'a' - 'ã' -> 'a' - 'ä' -> 'a' - 'ç' -> 'c' - 'è' -> 'e' - 'é' -> 'e' - 'ê' -> 'e' - 'ë' -> 'e' - 'ì' -> 'i' - 'í' -> 'i' - 'î' -> 'i' - 'ï' -> 'i' - 'ñ' -> 'n' - 'ò' -> 'o' - 'ó' -> 'o' - 'ô' -> 'o' - 'õ' -> 'o' - 'ö' -> 'o' - 'š' -> 's' - 'ù' -> 'u' - 'ú' -> 'u' - 'û' -> 'u' - 'ü' -> 'u' - 'ý' -> 'y' - 'ÿ' -> 'y' - 'ž' -> 'z' - _ -> c |