{"id":17963057,"url":"https://github.com/evancz/url-parser","last_synced_at":"2025-06-30T20:05:25.310Z","repository":{"id":62418475,"uuid":"59340409","full_name":"evancz/url-parser","owner":"evancz","description":"Parse URLs into nicely structured data","archived":false,"fork":false,"pushed_at":"2018-09-10T03:54:26.000Z","size":44,"stargazers_count":114,"open_issues_count":8,"forks_count":29,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-07T15:51:53.522Z","etag":null,"topics":["elm","navigation","routing","spa","url"],"latest_commit_sha":null,"homepage":"http://package.elm-lang.org/packages/evancz/url-parser/latest/","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evancz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-21T03:48:00.000Z","updated_at":"2024-01-06T00:48:27.000Z","dependencies_parsed_at":"2022-11-01T16:46:18.107Z","dependency_job_id":null,"html_url":"https://github.com/evancz/url-parser","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/evancz/url-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evancz%2Furl-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evancz%2Furl-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evancz%2Furl-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evancz%2Furl-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evancz","download_url":"https://codeload.github.com/evancz/url-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evancz%2Furl-parser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262842921,"owners_count":23373166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elm","navigation","routing","spa","url"],"created_at":"2024-10-29T11:23:40.983Z","updated_at":"2025-06-30T20:05:25.213Z","avatar_url":"https://github.com/evancz.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# URL Parser\n\nThis library helps you turn URLs into nicely structured data.\n\nIt is designed to be used with `elm-lang/navigation` to help folks create single-page applications (SPAs) where you manage browser navigation yourself.\n\n\u003e **Note:** This library is meant to serve as a baseline for future URL parsers. For example, it does not handle query parameters and hashes right now. It is more to (1) get folks started using URL parsers and (2) help us gather data on exactly which scenarios people face.\n\n\n## Examples\n\nHere is a simplified REPL session showing a parser in action:\n\n```elm\n\u003e import UrlParser exposing ((\u003c/\u003e), s, int, string, parseHash)\n\n\u003e parseHash (s \"blog\" \u003c/\u003e int) { ... , hash = \"#blog/42\" }\nJust 42\n\n\u003e parseHash (s \"blog\" \u003c/\u003e int) { ... , hash = \"#/blog/13\" }\nJust 13\n\n\u003e parseHash (s \"blog\" \u003c/\u003e int) { ... , hash = \"#/blog/hello\" }\nNothing\n\n\u003e parseHash (s \"search\" \u003c/\u003e string) { ... , hash = \"#search/dogs\" }\nJust \"dogs\"\n\n\u003e parseHash (s \"search\" \u003c/\u003e string) { ... , hash = \"#/search/13\" }\nJust \"13\"\n\n\u003e parseHash (s \"search\" \u003c/\u003e string) { ... , hash = \"#/search\" }\nNothing\n```\n\nNormally you have to put many of these parsers to handle all possible pages though! The following parser works on URLs like `/blog/42` and `/search/badger`:\n\n```elm\nimport UrlParser exposing (Parser, (\u003c/\u003e), s, int, string, map, oneOf, parseHash)\n\ntype Route = Blog Int | Search String\n\nroute : Parser (Route -\u003e a) a\nroute =\n  oneOf\n    [ map Blog (s \"blog\" \u003c/\u003e int)\n    , map Search (s \"search\" \u003c/\u003e string)\n    ]\n\n-- parseHash route { ... , hash = \"#/blog/58\" }    == Just (Blog 58)\n-- parseHash route { ... , hash = \"#/search/cat\" } == Just (Search \"cat\")\n-- parseHash route { ... , hash = \"#/search/31\" }  == Just (Search \"31\")\n-- parseHash route { ... , hash = \"#/blog/cat\" }   == Nothing\n-- parseHash route { ... , hash = \"#/blog\" }       == Nothing\n```\n\nNotice that we are turning URLs into nice [union types](https://guide.elm-lang.org/types/union_types.html), so we can use `case` expressions to work with them in a nice way.\n\nCheck out the `examples/` directory of this repo to see this in use with `elm-lang/navigation`.\n\n\n## Testing\n\n```\nnpm install\nnpm test\n```\n\n## Background\n\nI first saw this general idea in Chris Done\u0026rsquo;s [formatting][] library. Based on that, Noah and I outlined the API you see in this library. Noah then found Rudi Grinberg\u0026rsquo;s [post][] about type safe routing in OCaml. It was exactly what we were going for. We had even used the names `s` and `(\u003c/\u003e)` in our draft API! In the end, we ended up using the \u0026ldquo;final encoding\u0026rdquo; of the EDSL that had been left as an exercise for the reader. Very fun to work through!\n\n[formatting]: http://chrisdone.com/posts/formatting\n[post]: http://rgrinberg.com/posts/primitive-type-safe-routing/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevancz%2Furl-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevancz%2Furl-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevancz%2Furl-parser/lists"}