arowM / elm-decimal-char / DecimalChar

Provide functions to handle Unicode decimal characters, which are listed in DerivedNumericType-15.0.0.txt as Numeric_Type=Decimal.

You can use this library to normalize user inputs, which will free users from the hassle of entering numbers in the "correct" format.

isDecimal : Char -> Basics.Bool

Check if a character is decimal (i.e., Numeric_Type=Decimal).

isDecimal '3'
--> True

isDecimal '3'
--> True

isDecimal '🐐'
--> False

-- Roman digit is numeric, but not decimal.
isDecimal 'Ⅵ'
--> False

isBasicLatin : Char -> Basics.Bool

Check if a character is the Basic Latin digit (i.e., between 0x0030 and 0x0039 in code points).

isBasicLatin '3'
--> True

isBasicLatin '3'
--> False

toBasicLatin : Char -> Maybe Char

Convert a character to the corresponding Basic Latin digit character.

If the character is not decimal, it returns Nothing.

toBasicLatin '3'
--> Just '3'

-- Arabic numeral representing '9'
toBasicLatin '٩'
--> Just '9'

toBasicLatin '🐐'
--> Nothing

normalizeAsDigits : String -> String

Extract only the decimal characters contained in a given string, and convert them to the corresponding Basic Latin characters.

normalizeAsDigits "0123🐐45٩🌱"
--> "0123459"

normalizeAsText : String -> String

Similar to normalizeAsDigits, but normalizeAsText leaves non-decimal characters as they are.

normalizeAsText "0123🐐45٩🌱"
--> "0123🐐459🌱"