Represents the path portion of a URL (not query parameters, fragment, protocol, port, etc.).
This helper lets you combine together path parts without worrying about having too many or too few slashes. These two examples will result in the same URL, even though the first example has trailing and leading slashes, and the second does not.
Path.join [ "/blog/", "/post-1/" ]
|> Path.toAbsolute
--> "/blog/post-1"
Path.join [ "blog", "post-1" ]
|> Path.toAbsolute
--> "/blog/post-1"
We can also safely join Strings that include multiple path parts, a single path part per string, or a mix of the two:
Path.join [ "/articles/archive/", "1977", "06", "10", "post-1" ]
|> Path.toAbsolute
--> "/articles/archive/1977/06/10/post-1"
Create a Path from multiple path parts. Each part can either be a single path segment, like blog
, or a
multi-part path part, like blog/post-1
.
Create a Path from a path String.
Path.fromString "blog/post-1/"
|> Path.toAbsolute
|> Expect.equal "/blog/post-1"
Turn a Path to an absolute URL (with no trailing slash).
Turn a Path to a relative URL.
The path portion of the URL, normalized to ensure that path segments are joined with
/
s in the right places (no doubled up or missing slashes).