Shikensu.Path
Paths
type Path kind
Path type. This is used with the phantom 👻 types.
directoryPath : Path Directory
filePath : Path File
encapsulatedPath : Path Encapsulated
type Directory
👻 Directory
type File
👻 File
type Encapsulated
👻 Encapsulated
type Kind
= Directory
| File
Creation
directory :
Array String -> Path Directory
Create a directory path. directory [ "Audio", "Playlists" ]
file :
Array String -> Path File
Create a file path. file [ "Document", "invoice.pdf" ]
currentWorkingDirectory :
Permission -> Task Never (Path Directory)
Get the directory path of the current working directory.
POSIX
fromPosix :
String -> Path Encapsulated
Convert a POSIX formatted string to a path.
This will return a Encapsulated
path. To get a path of the type Path Directory
or Path File
, use the functions in the Webnative.Path.Encapsulated
module.
>>> import Webnative.Path.Encapsulated
>>> "foo/bar/"
..> |> fromPosix
..> |> Webnative.Path.Encapsulated.toDirectory
Just (directory [ "foo", "bar" ])
>>> "foo/bar"
..> |> fromPosix
..> |> Webnative.Path.Encapsulated.toFile
Just (file [ "foo", "bar" ])
toPosix :
{ absolute : Bool } -> Path kind -> String
Convert a path to the POSIX format.
>>> toPosix { absolute = True } (directory [ "foo", "bar"])
"/foo/bar/"
>>> toPosix { absolute = False } (file [ "foo", "bar"])
"foo/bar"
Encapsulation
encapsulate :
Path kind -> Path Encapsulated
Encapsulate a path.
Functions
combine :
Path Directory -> Path kind -> Path kind
Combine a directory path and another path.
kind :
Path kind -> Kind
Get the path kind.
>>> kind (directory [])
Directory
>>> kind (file [])
File
Even if a path is encapsulated, you can still check the kind of path it is.
>>> kind (encapsulate <| directory [])
Directory
>>> kind (encapsulate <| file [])
File
length :
Path kind -> Int
Length.
map :
(Array String -> Array String) -> Path kind -> Path kind
Map.
unwrap :
Path kind -> Array String
Get the path parts.
>>> unwrap (directory [ "foo", "bar" ])
[ "foo", "bar" ]
>>> unwrap (file [ "foo", "bar" ])
[ "foo", "bar" ]