Skip to content

Instantly share code, notes, and snippets.

@maxfarseer
Created April 26, 2020 14:40
Show Gist options
  • Save maxfarseer/805e94010933c74c1f9d518dadb33016 to your computer and use it in GitHub Desktop.
Save maxfarseer/805e94010933c74c1f9d518dadb33016 to your computer and use it in GitHub Desktop.
Base64ImgUrl fixed
module Base64 exposing (Base64ImgUrl, decoderStringToBase64ImgUrl, fromString, toString)
import Json.Decode as JD
import String exposing (startsWith)
type Base64ImgUrl
= Base64ImgUrl String
toString : Base64ImgUrl -> String
toString (Base64ImgUrl str) =
str
fromString : String -> Base64ImgUrl
fromString str =
if startsWith "data:image" str then
Base64ImgUrl str
else
Base64ImgUrl ("data:image/png;base64, " ++ str)
-- Decoders
decoderStringToBase64ImgUrl : JD.Decoder Base64ImgUrl
decoderStringToBase64ImgUrl =
JD.map fromString JD.string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment