Skip to content

husseymarcos/url_join

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

url_join

Package Version Hex Docs

Join URL path segments and normalize the result, similar to npm's url-join.

Installation

gleam add url_join

Usage

import url_join

pub fn main() -> Nil {
  // Join segments and normalize slashes, protocol, query, and hash
  let url =
    url_join.join([
      "http://www.google.com",
      "a",
      "/b/cd",
      "?foo=123",
    ])
  // -> "http://www.google.com/a/b/cd?foo=123"

  let api =
    url_join.join([
      "https://example.com/",
      "/api/",
      "users",
    ])
  // -> "https://example.com/api/users"
}

Behaviour

  • Filters out empty segments
  • Merges a leading bare protocol (e.g. "http:") with the next segment
  • Merges a leading "/" with the next segment
  • Normalises protocols to protocol:// (and file:/// for file)
  • Trims and collapses slashes between segments
  • Does not add a slash before ?, #, or &
  • Normalises query string (multiple ?/& become a single ? then &)

Further documentation can be found at https://hexdocs.pm/url_join.

Development

gleam run   # Run the project
gleam test  # Run the tests

About

Join URL path segments and normalize the result.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages