A module to handle data URLs (IETF RFC 2397) in type safe manner.
The data URL string is supposed to be provided through ports.
Reexport Data type from DataUrl.Data for convenience.
Reexport MediaType type from DataUrl.MediaType for convenience.
The only way to construct DataUrl value.
It takes a String representation of data URL and parses it as a DataUrl value.
If the provided String argument is illigal as a data URL, it returns Nothing.
Note that it does not accept raw HTML string, though data URLs page of MDN has such an example.
fromString "data:text/html,<script>alert('hi');</script>"
--> NothingTake MediaType value from DataUrl value.
As data URLs page of MDN says,
it should be assumed that text/plain;charset=US-ASCII is set when the value is Nothing.
Take data part from DataUrl.
It is guaranteed that the data URL has base64 token when the value is Base64 someString, but the someString could be illegal base64 string as follows.
import DataUrl.Data exposing(Data(..))
Maybe.map data <| fromString "data:text/plain;base64,This-is?illegal%base64_string"
--> Just <| Base64 "This-is?illegal%base64_string"The someString is only guaranteed to meet uric of RFC 2396.
Convert DataUrl values to String.
Maybe.map DataUrl.toString <|
fromString "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D"
--> Just "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D"A parser for DataUrl.
Use fromString for simple usage.
An opaque type representing data url