Internal.Path
Parsed and normalised path.
Internal.Platform
Represents a platform used for parsing the strings, either Win32 or Posix.
Create or infer platforms with Path.Platform
fromString : Platform -> String -> Result String Path
Create a path from a string. The path will be normalised and any trailing slashes will be dropped. Note this will not raise an error on invalid path characters
Result.map Path.toString (Path.fromString Path.Platform.posix "/static/images/image.jpeg/" ]) == Ok "/static/images/image.jpeg"
Result.map Path.toString (Path.fromString Path.Platform.posix "../..//.///foo") == Ok "../../foo"
Result.map Path.toString (Path.fromString Path.Platform.posix "./x/b/..//b/c.js") == Ok "x/b/c.js"
Result.map Path.toString (Path.fromString Path.Platform.win32 "a:\\b") == Ok "a:\\b"
Result.map Path.toString (Path.fromString Path.Platform.win32 "\\\\machine\\server\\\\path") == Ok "\\\\machine\\server\\path"
Result.map Path.toString (Path.fromString Path.Platform.posix "") == Ok "."
Result.map Path.toString (Path.fromString Path.Platform.posix " foo") == Ok " foo"
toString : Path -> String
Turn a path into a string.
Result.map Path.toString (Path.fromString Path.Platform.posix "/static/images/image.jpeg/") == Ok "/static/images/image.jpeg"
Result.map Path.toString (Path.fromString Path.Platform.win32 "c:\\static\\images\\image.jpeg") == Ok "c:\\static\\images\\image.jpeg"
Result.map Path.toString (Path.fromString Path.Platform.posix "static/////images///image.jpeg///////") == Ok "static/images/image.jpeg"
Result.map Path.toString (Path.fromString Path.Platform.posix "") == Ok "."
Result.map Path.toString (Path.fromString Path.Platform.posix "a/../b/./c/../") == Ok "b"
fromList : Platform -> List String -> Result String Path
Create a path from a list of strings. Some notes:
If passed a path with a root, it will not overwrite previous segments, it will add the root to the path. This is similar to Node path behaviour and different from Python os.path behaviour.
If passed a valid root as the first element in the list, will not add a separator between the first and second elements
Will ignore empty strings
Won't ignore spaces!
Result.map Path.toString (Path.fromList Path.Platform.posix [ "/static", "images", "/image.jpeg" ]) == Ok "/static/images/image.jpeg"
Result.map Path.toString (Path.fromList Path.Platform.posix [ "", "..", "..", "/foo" ]) == Ok "../../foo"
Result.map Path.toString (Path.fromList Path.Platform.posix [ ".", "x/b", "..", "/b/c.js" ]) == Ok "x/b/c.js"
Result.map Path.toString (Path.fromList Path.Platform.win32 [ "a:", "\\b" ][ "a:", "\b" ][ "a:", "\\b" ]) == Ok "a:\\b"
Result.map Path.toString (Path.fromList Path.Platform.win32 [ "a:", "b\\c" ][ "a:", "b\c" ][ "a:", "b\\c" ]) == Ok "a:b\\c"
Result.map Path.toString (Path.fromList Path.Platform.posix []) == Ok "."
Result.map Path.toString (Path.fromList Path.Platform.posix [ " ", "foo" ]) == Ok " /foo"
toList : Path -> List String
Turn a path into a list of directory and file name segments. Includes the path root.
Result.map Path.toList (Path.fromString "/static/images/image.jpeg") == Ok [ "/", "static", "images", "image.jpeg" ]
Result.map Path.toList (Path.fromString "c:\\static\\images\\image.jpeg") == Ok [ "c:\\", "static", "images", "image.jpeg" ]
Result.map Path.toList (Path.fromString "static/images/image.jpeg") == Ok [ "static", "images", "image.jpeg" ]
separator : Path -> String
Get the separator of a path.
Result.map Path.separator (Path.fromString Path.Platform.posix "/static/images/image.jpeg/" ]) == Ok "/"
Result.map Path.separator (Path.fromString Path.Platform.posix "../..//.///foo") == Ok "/"
Result.map Path.separator (Path.fromString Path.Platform.win32 "./x/b/..//b/c.prod.js") == Ok "\\"
Result.map Path.separator (Path.fromString Path.Platform.posix "./x/b/..//b/.hidden") == Ok "/"
delimiter : Path -> String
Get the delimiter of a path.
Result.map Path.delimiter (Path.fromString Path.Platform.posix "/static/images/image.jpeg/" ]) == Ok ":"
Result.map Path.delimiter (Path.fromString Path.Platform.posix "../..//.///foo") == Ok ":"
Result.map Path.delimiter (Path.fromString Path.Platform.win32 "./x/b/..//b/c.prod.js") == Ok ";"
Result.map Path.delimiter (Path.fromString Path.Platform.posix "./x/b/..//b/.hidden") == Ok ":"
platform : Path -> Platform
Get the platform of a path.
Result.map Path.platform (Path.fromString Path.Platform.posix "/static/images/image.jpeg/" ]) == Ok Path.Platform.posix
Result.map Path.platform (Path.fromString Path.Platform.posix "../..//.///foo") == Ok Path.Platform.posix
Result.map Path.platform (Path.fromString Path.Platform.win32 "./x/b/..//b/c.prod.js") == Ok Path.Platform.win32
Result.map Path.platform (Path.fromString Path.Platform.posix "./x/b/..//b/.hidden") == Ok Path.Platform.posix
dir : Path -> String
Get the directory of a path.
Result.map Path.dir (Path.fromString Path.Platform.posix "/static/images/image.jpeg/" ]) == Ok "/static/images"
Result.map Path.dir (Path.fromString Path.Platform.posix "../..//.///foo") == Ok "../.."
Result.map Path.dir (Path.fromString Path.Platform.posix "./x/b/..//b/c.prod.js") == Ok "x/b"
Result.map Path.dir (Path.fromString Path.Platform.posix "./x/b/..//b/.hidden") == Ok "x/b"
base : Path -> String
Get the full file name or last directory name of a path.
Result.map Path.base (Path.fromString Path.Platform.posix "/static/images/image.jpeg/" ]) == Ok "image.jpeg"
Result.map Path.base (Path.fromString Path.Platform.posix "../..//.///foo") == Ok "foo"
Result.map Path.base (Path.fromString Path.Platform.posix "./x/b/..//b/c.prod.js") == Ok "c.prod.js"
Result.map Path.base (Path.fromString Path.Platform.posix "./x/b/..//b/.hidden") == Ok ".hidden"
name : Path -> String
Get the file name (without extension) or last directory name of a path. Will take from the left of the last ".".
Result.map Path.name (Path.fromString Path.Platform.posix "/static/images/image.jpeg/" ]) == Ok "image"
Result.map Path.name (Path.fromString Path.Platform.posix "../..//.///foo") == Ok "foo"
Result.map Path.name (Path.fromString Path.Platform.posix "./x/b/..//b/c.prod.js") == Ok "c.prod"
Result.map Path.name (Path.fromString Path.Platform.posix "./x/b/..//b/.hidden") == Ok ".hidden"
ext : Path -> String
Get the file extension (if it exists) of a path. Will only take from the last ".".
Result.map Path.ext (Path.fromString Path.Platform.posix "/static/images/image.jpeg/" ]) == Ok ".jpeg"
Result.map Path.ext (Path.fromString Path.Platform.posix "../..//.///foo") == Ok ""
Result.map Path.ext (Path.fromString Path.Platform.posix "./x/b/..//b/c.prod.js") == Ok ".js"
Result.map Path.ext (Path.fromString Path.Platform.posix "./x/b/..//b/.hidden") == Ok ""