A mask is a formatting pattern that you can apply to a value. This module has some functions to help you create and apply masks.
string : String -> String -> String
Formats a string using a pattern. A pattern is a string where the #
is going to be replaced by a character of the input
string "#-##-#" "1b0a" == "1-b0-a"
string "FOO##.###.##BAR" "EXAMPLE" == "FOEX.AMP.LEBAR"
number : String -> String -> String
Formats a string filtering only the numbers of it
number "(##) ####-####" "1234567890" == "(12) 3456-7890"
number "#-##-#" "1b0a" == "1-0"
{ decimal : String
, thousand : String
, precision : Basics.Int
}
Options used to format numbers. decimal
and thousand
are the characters that separate each section of the number and precision
is the number of decimal places
defaultDecimalOptions : DecimalOptions
Default options to format numbers. Extend this if you want to customize the way numbers are formatted.
defaultDecimalOptions =
{ decimal = "."
, thousand = ","
, precision = 2
}
floatDecimal : DecimalOptions -> Basics.Float -> String
Formats a Float
number according to the specified options
floatDecimal defaultDecimalOptions 10500.5 == "10.500.50"
floatDecimal { defaultDecimalOptions | precision = 3, decimal = ",", thousand = "." } 10500.5 == "10.500,500"
intDecimal : DecimalOptions -> Basics.Int -> String
Formats a Int
number according to the specified options
intDecimal defaultDecimalOptions 105005 == "1,050.05"
intDecimal { defaultDecimalOptions | precision = 3, decimal = "," } 105005 == "105,005"