NeoVier/elm-mask/1.0.0

NOTE: the latest version is 2.0.4

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.

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/henriquecbuss/elm-mask.

What we checked: The repo moved to github.com/henriquecbuss/elm-mask. Rebuilt with git archive from commit e020c8b9034b of https://github.com/henriquecbuss/elm-mask (zip prefix NeoVier-elm-mask-e020c8b/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 7819731a56e061c38ac09a704070951cb33ab3b6.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/NeoVier/elm-mask/zipball/1.0.0/

Mask

This library helps you mask Strings and Floats

Strings

{ mask : String
, replace : Char
}
-> String
-> String

Apply a simple mask to a String. You can customize the mask template and which Char to replace.

string { mask = "+1 ### ### ####", replace = '#' } "1234567890"
--> "+1 123 456 7890"
{ mask : String
, replace : Char
}
-> String
-> String

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"

Floats

= Precisely Int
| AtMost Int

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.

float : DecimalDigits -> Float -> String

Mask a float to have a certain amount of DecimalDigits.

float (Precisely 2) 123
--> "123.00"


float (Precisely 2) 123.4
--> "123.40"


float (Precisely 2) 123.4567
--> "123.45"


float (AtMost 2) 123
--> "123"


float (AtMost 2) 123.4
--> "123.4"


float (AtMost 2) 123.4567
--> "123.45"
floatString : DecimalDigits -> String -> Maybe String

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) "123.4"
--> Just "123.40"


floatString (Precisely 2) "12a.4"
--> Nothing


floatString (Precisely 2) ""
--> 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
            }