fredcy/elm-parseint/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

ParseInt

Convert String value to Int.

Functions

parseInt : String -> Result Error Int

Convert String to Int assuming base 10.

parseInt "314159" == Ok 314159
parseInt "foo" = Err (OutOfRange 'o')
parseIntOct : String -> Result Error Int

Convert String to Int assuming base 8 (octal). No leading '0' is required.

parseIntHex : String -> Result Error Int

Convert String to Int assuming base 16 (hexadecimal). No leading characters are expected; input starting with "0x" (or any other out of range character) will cause an Err return.

parseIntRadix : Int -> String -> Result Error Int

Convert String to Int assuming given radix. Radix can be any of 2..36. Leading zeroes are ignored. Valid characters are the alphanumerics: those in the ASCII range [0-9a-zA-Z]. Case does not matter. For radixes beyond 16 the normal [A-F] range for hexadecimal is extended in the natural way. Any invalid character results in a Err return. Any valid character outside of the range defined by the radix also results in an Err. An Ok return means that the entire input string was consumed. The empty string results in Ok 0

parseIntRadix 16 "DEADBEEF" = Ok 3735928559

Errors

type Error
= InvalidChar Char
| OutOfRange Char
| InvalidRadix Int

Possible Result.Err returns from the parseInt functions.