aboutsummaryrefslogtreecommitdiff
path: root/src/Format.purs
diff options
context:
space:
mode:
authorJoris2017-04-09 00:37:59 +0200
committerJoris2017-04-09 00:37:59 +0200
commit69be67a67503c0cb80153510083513f92de952bf (patch)
tree62de654cdcc1efeea25788f9e80d69b4f01a1fab /src/Format.purs
parentba548aafb4dcad5d7d69ef85b9b13e852facd31d (diff)
Add food
Diffstat (limited to 'src/Format.purs')
-rw-r--r--src/Format.purs50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/Format.purs b/src/Format.purs
index 22593e5..bed5927 100644
--- a/src/Format.purs
+++ b/src/Format.purs
@@ -1,12 +1,17 @@
-module Format where
+module Format
+ ( number
+ , compare
+ , unaccent
+ ) where
import Data.Int (toNumber, fromNumber)
import Data.Array (replicate)
import Data.Maybe (fromMaybe)
-import Data.String (length, joinWith)
+import Data.String (length, joinWith, fromCharArray, toCharArray, toLower)
import Math (round, trunc, pow)
-import Prelude
+import Prelude hiding (compare)
+import Prelude as Prelude
number :: Int -> Number -> String
number decimalLength num = formattedIntegerPart <> formattedDecimalPart
@@ -27,3 +32,42 @@ number decimalLength num = formattedIntegerPart <> formattedDecimalPart
# \str -> "," <> (joinWith "" $ replicate (decimalLength - length str) "0") <> str
else
""
+
+compare :: String -> String -> Ordering
+compare xs ys = Prelude.compare (formatString xs) (formatString ys)
+ where formatString = 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