A URL parsing and construction library for ELM
As of Elm 0.19, Elm core has a package works very similarly to Erl. See https://package.elm-lang.org/packages/elm/url/latest/Url#fromString.
-- Given a url string
url = "http://sam:pass@api.example.com:3000/products/kids?color=red&age=10#toys/1"
Erl.parse url
-- Returns a Erl.Url record:
{ protocol = "http"
, host = "api.example.com"
, port_ = Just 3000
, pathname = "/products/kids"
, query = [ ( "color", "red" ), ( "age", "10") ]
, hash = "#toys/1"
}
See MDN for more details (https://developer.mozilla.org/en-US/docs/Web/API/Location). Note that in MDN query
is called search
.
-- Given a Erl.Url record (url):
Erl.toString url
-- Returns the url as string:
"http://www.foo.com:2000/users/1?k=2&q=1#a/b"
There are many ways to parse query strings. E.g. an array might be a[]=1&a[]=2
or a=1&a=2
depending on the web framework or library.
Erl parses the query into a List (String, String)
. This is a bit more useful than just a string, but not as opinionated as other libraries.
Documentation at package.elm-lang.org
yarn install
npm test