Renamed to henriquecbuss/elm-mask. It is published under that name, and new versions come out there.
Versions published as NeoVier/elm-mask still install under that name. 2 versions of 6 come from the new location (see their notes). 4 versions could not be recovered and cannot be installed.
Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/henriquecbuss/elm-mask exists but has no tag 2.0.4; Software Heritage not asked yet (this run's --swh-calls were used up); no fork with tag 2.0.4 found (5 same-name repos checked); no cached copy. Use another version.
This library helps you mask Strings and Floats
Remove a mask applied by string. This is often needed if you
want to save just the value, and not the formatted/masked String.
remove { mask = "+1 ### ### ####", replace = '#' } "+1 123 456 7890"
--> "1234567890"
remove { mask = "+1 ### ### ####", replace = '#' } "1234567890"
-->"1234567890"When formatting with float and floatString, it can be useful to either use
exactly an amount of decimal digits, or just to limit it to a certain amount.
Mask a float to have a certain amount of DecimalDigits.
float (Precisely 2) { decimalSeparator = ".", thousandsSeparator = "" } 1234
--> "1234.00"
float (Precisely 2) { decimalSeparator = ",", thousandsSeparator = " " } 1234.5
--> "1 234,50"
float (Precisely 2) { decimalSeparator = ",", thousandsSeparator = "" } 123.4567
--> "123,45"
float (AtMost 2) { decimalSeparator = ".", thousandsSeparator = "," } 123
--> "123"
float (AtMost 2) { decimalSeparator = ".", thousandsSeparator = "," } 123.4
--> "123.4"
float (AtMost 2) { decimalSeparator = ".", thousandsSeparator = "," } 123.4567
--> "123.45"Mask a float to have a certain amount of DecimalDigits,
but using a String as an input. This is useful for input fields, where the
onInput event returns a String that can be run through floatString. In
case the input String is not a valid Float, this function returns Nothing,
and an empty String is automatically converted to 0.
floatString (Precisely 2) { decimalSeparator = ",", thousandsSeparator = " " } "1234.5"
--> Just "1 234,50"
floatString (Precisely 2) { decimalSeparator = ".", thousandsSeparator = "," } "12a.4"
--> Nothing
floatString (Precisely 2) { decimalSeparator = ",", thousandsSeparator = "." } ""
--> Just "0,00"Usually you'll want to use this function in your update like this:
update msg model =
case msg of
EnteredPrice price ->
{ model
| price =
price
|> Mask.floatString (Mask.Precisely 2)
|> Maybe.withDefault model.price
}Remove a mask applied by float or floatString
removeFloat { decimalSeparator = ",", thousandsSeparator = " " } "1 234,56"
--> "1234.56"A default value you can use for float and floatString.
Update a masked value you store in your Model. This is useful to provide a
better UX when using masked input fields. For more details, check out
this example on GitHub
or in this Ellie link, which uses a
custom element to
make it even better!
Apply a simple mask to a
String. You can customize the mask template and whichCharto replace.