NeoVier/elm-eos/1.0.0

Renamed to henriquecbuss/elm-eos. It is published under that name, and new versions come out there.

Versions published as NeoVier/elm-eos still install under that name. 1 version of 1 come from the new location (see their notes).

Rerouted (renamed, needs approval). 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-eos.

What we checked: The repo moved to github.com/henriquecbuss/elm-eos and tag 1.0.0 is there; its commit 12b679fbd416 is from 2022-11-04 12:13 UTC, after the version was published (2022-11-04 02:04 UTC); elm.json differs from package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one and nothing else confirms its contents.

We could not verify this copy against what was published, so the Lamdera compiler asks before using it (y/n). Without a terminal, as in CI, it stops with an error unless approved:

  • lamdera make --auto-approve-package-rerouting approves rerouted versions for that run,
  • LAMDERA_AUTO_APPROVE_PACKAGE_REROUTING=1 does the same for every run in that environment,
  • LAMDERA_CACHE=off skips the Lamdera package server altogether: packages come from package.elm-lang.org and GitHub only, as with elm, and a rerouted version then fails to download.

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

Eos.Symbol

type Symbol

A Symbol is what identifies a currency, and is made of a precision and a SymbolCode. For example, the symbol 1,EOS is a symbol with precision 1, and a symbol code of EOS.

The precision number determines how many decimal digits can be used. In the example above, someone can have 0.1 EOS, but not 0.01 EOS.

Extracting information

precision : Symbol -> Int

Get the precision of a Symbol.

fromPrecisionAndCodeString 1 "EOS"
    |> Result.map precision
--> Ok 1

Get the SymbolCode of a Symbol

import Eos.SymbolCode


fromPrecisionAndCodeString 1 "EOS"
    |> Result.map (code >> Eos.SymbolCode.toString)
--> Ok "EOS"

Converting from Strings and Ints

fromPrecisionAndCodeString : Int -> String -> Result Error Symbol

Create a Symbol from a precision and a String that represents a SymbolCode. If you already have a SymbolCode, use fromPrecisionAndCode instead.

import Eos.SymbolCode


fromPrecisionAndCodeString 1 "EOS"
    |> Result.map
        (\symbol ->
            { precision = precision symbol
            , codeString = Eos.SymbolCode.toString (code symbol)
            }
        )
--> Ok { precision = 1, codeString = "EOS" }


fromPrecisionAndCodeString -1 "EOS"
--> Err (PrecisionError NegativePrecision)


fromPrecisionAndCodeString 1 "eos"
--> Err (SymbolCodeError (Eos.SymbolCode.InvalidCharacters ( 'e', [ 'o', 's' ] )))

Create a Symbol from a precision and a SymbolCode.

type Error
= PrecisionError PrecisionError
| SymbolCodeError Error

When creating a Symbol, there are two things we validate: the precision and the symbol code. This type represents that.

= NegativePrecision

Precisions must be >= 0. This type represents the error that can happen when trying to create a Symbol with a negative precision.

errorToString : Error -> String

You can use this function to convert an Error to a human-readable String.

Dealing with JSON

encode : Symbol -> Value

Encode a Symbol into a JSON value.

decoder : Decoder Symbol

Decode a Symbol from a JSON value.