fission-codes/webnative-elm/2.0.0

NOTE: the latest version is 3.0.0

Formerly fission-suite/webnative-elm. Search finds this package by either name.

Webnative.Path

Paths

type Path t

Path type.

This is used with the phantom 👻 types.

directoryPath : Path Directory


filePath : Path File


encapsulatedPath : Path Encapsulated

👻 Directory

type File

👻 File

👻 Encapsulated

type Kind
= Directory
| File

Creation

directory : List String -> Path Directory

Create a directory path.

directory [ "Audio", "Playlists" ]
file : List String -> Path File

Create a file path.

file [ "Document", "invoice.pdf" ]

Root directory.

POSIX

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 : Path t -> String

Convert a path to the POSIX format.

>>> toPosix (directory [ "foo", "bar"])
"foo/bar/"


>>> toPosix (file [ "foo", "bar"])
"foo/bar"

Encapsulation

Encapsulate a path.

Functions

kind : Path t -> 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
map : (List String -> List String) -> Path t -> Path t

Map.

unwrap : Path t -> List String

Get the path parts.

>>> unwrap (directory [ "foo", "bar" ])
[ "foo", "bar" ]


>>> unwrap (file [ "foo", "bar" ])
[ "foo", "bar" ]

Miscellaneous

encode : Path t -> Value

Encode to JSON.

>>> import Json.Encode


>>> [ "foo" ]
..>   |> directory
..>   |> encode
..>   |> Json.Encode.encode 0
"{\"directory\":[\"foo\"]}"


>>> [ "bar" ]
..>   |> file
..>   |> encode
..>   |> Json.Encode.encode 0
"{\"file\":[\"bar\"]}"