Externalize strings in other of components

This commit is contained in:
Eike Kettner
2021-04-09 22:39:44 +02:00
parent 2f678aca17
commit fa2c5750dd
53 changed files with 490 additions and 223 deletions

View File

@ -1,5 +1,6 @@
module Data.Money exposing
( Money
, MoneyParseError(..)
, format
, fromString
, normalizeInput
@ -11,7 +12,12 @@ type alias Money =
Float
fromString : String -> Result String Money
type MoneyParseError
= RequireTwoDigitsAfterDot String
| NoOrTooManyPoints String
fromString : String -> Result MoneyParseError Money
fromString str =
let
input =
@ -28,13 +34,13 @@ fromString str =
if index == (len - 3) then
String.toFloat input
|> Maybe.map Ok
|> Maybe.withDefault (Err "Two digits required after the dot.")
|> Maybe.withDefault (Err (RequireTwoDigitsAfterDot str))
else
Err ("Two digits required after the dot: " ++ str)
Err (RequireTwoDigitsAfterDot str)
_ ->
Err "One single dot + digits required for money."
Err (NoOrTooManyPoints str)
format : Float -> String