Created
April 26, 2020 14:40
-
-
Save maxfarseer/805e94010933c74c1f9d518dadb33016 to your computer and use it in GitHub Desktop.
Base64ImgUrl fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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