mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-25 21:02:33 +03:00
Add Path.fromString.
This commit is contained in:
parent
8a982aa884
commit
b147d17a1d
29
src/Path.elm
29
src/Path.elm
@ -1,4 +1,7 @@
|
||||
module Path exposing (Path, join, toAbsolute)
|
||||
module Path exposing
|
||||
( Path, join, fromString
|
||||
, toAbsolute
|
||||
)
|
||||
|
||||
{-| Represents the path portion of a URL (not query parameters, fragment, protocol, port, etc.).
|
||||
|
||||
@ -14,7 +17,15 @@ second does not.
|
||||
|> Path.toAbsolute
|
||||
--> "/blog/post-1"
|
||||
|
||||
@docs Path, join, toAbsolute
|
||||
|
||||
## Creating Paths
|
||||
|
||||
@docs Path, join, fromString
|
||||
|
||||
|
||||
## Turning Paths to String
|
||||
|
||||
@docs toAbsolute
|
||||
|
||||
-}
|
||||
|
||||
@ -31,6 +42,20 @@ join parts =
|
||||
|> Path
|
||||
|
||||
|
||||
{-| Create a Path from a path String.
|
||||
|
||||
Path.fromString "blog/post-1/"
|
||||
|> Path.toAbsolute
|
||||
|> Expect.equal "/blog/post-1"
|
||||
|
||||
-}
|
||||
fromString : String -> Path
|
||||
fromString path =
|
||||
path
|
||||
|> normalize
|
||||
|> Path
|
||||
|
||||
|
||||
toAbsolute : Path -> String
|
||||
toAbsolute (Path path) =
|
||||
"/" ++ path
|
||||
|
@ -22,4 +22,14 @@ all =
|
||||
Path.join [ "a/", "/b/", "/c/d/e/" ]
|
||||
|> Path.toAbsolute
|
||||
|> Expect.equal "/a/b/c/d/e"
|
||||
, test "fromString with trailing and leading" <|
|
||||
\() ->
|
||||
Path.fromString "/blog/post-1/"
|
||||
|> Path.toAbsolute
|
||||
|> Expect.equal "/blog/post-1"
|
||||
, test "fromString without trailing and leading" <|
|
||||
\() ->
|
||||
Path.fromString "blog/post-1"
|
||||
|> Path.toAbsolute
|
||||
|> Expect.equal "/blog/post-1"
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user