erl icon indicating copy to clipboard operation
erl copied to clipboard

URL parsing library for ELM

Erl

Codeship Status for sporto/erl

A URL parsing and construction library for ELM

elm/url/

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.

parse a url string

-- Given a url string
url = "http://sam:[email protected]: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.

toString

-- 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"

Query parsing

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

Documentation at package.elm-lang.org

Test

yarn install
npm test

Changelog