This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
eDSL for typesafe URL parsing
version 2.0.1
license MIT
native-modules False
elm-version 0.18.0 <= v <= 0.19.0
Tag 2.0.1
Committed At 2019-07-15 05:16:55 UTC
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1
elm-community/elm-test 4.0.0 <= v < 5.0.0 4.2.0




Build Status

An embedded DSL for a typesafe parsing of URL. It is designed for processing URLs of any complexity.

The library can parse single value, multiple values with the strict or arbitrary order and queries. It also allows writing typesafe parser for a query.

The library contains two main parts:

  • A DSL for building parsing tree
  • Function which performs parsing of a string in according to provided parsing tree


Parsing of a string form a simple path.

parseName: String -> Maybe String
parseName url =
    case parse (p "someUrl" </> str) url of
        Str name ->
            Just name
        _ ->

parseName "someUrl/userName"  -- Just "userName"

Parsing of an integer from a path which contains a query.

parseQuery: String -> Maybe Int
parseQuery url =
    case parse (p "someUrl" <?> (p "age" <=> int)) url of
        Integer age ->
            Just age
        _ ->

parseQuery "someUrl?age=10"  -- Just 10

Parsing of multiple values.

parseNameAndId: String -> Just ( String, Int )
parseNameAndId url = 
    case parse (p "someUrl" </> str </> int </> any ) url of
        MultiValue [ Str name, Integer id] ->
                    Just (name, id)
        _ ->

parseNameAndId "someUrl/userName/1/someRandomStuff"  -- Just ("userName", 1)

Error handling in case of unsuccesful parsing.

getDevider: String -> Result String Float
getDevider url =
    case (parse any </> float) url of
        Floating value->
            Ok value
        Failure err ->
            Err err
        _ ->
            Err "Unexpected path."

getDevider "10*3.1415"  -- Err "10*3.1415 does not contain /"


Feedback and contributions are very welcome.

For installation of local npm dependencies run:

npm install

For installation of local elm dependencies run:

npm run install

Repeat the same actions for tests folder.

Run tests from root folder by:

npm test

Any Elm CLI commands can be called by:

npm run elm [comands]