Data.Path.Pathy
- Package
- purescript-pathy
- Repository
- slamdata/purescript-pathy
#Unsandboxed Source
data Unsandboxed :: Type
The (phantom) type of unsandboxed paths.
#runFileName Source
runFileName :: FileName -> String
Unwraps the FileName
newtype.
#runDirName Source
runDirName :: DirName -> String
Unwraps the DirName
newtype.
#Path Source
data Path a b s
A type that describes a Path. All flavors of paths are described by this type, whether they are absolute or relative paths, whether they refer to files or directories, whether they are sandboxed or not.
- The type parameter
a
describes whether the path isRel
orAbs
. - The type parameter
b
describes whether the path isFile
orDir
. - The type parameter
s
describes whether the path isSandboxed
orUnsandboxed
.
To ensure type safety, there is no way for users to create a value of
this type directly. Instead, helpers should be used, such as rootDir
,
currentDir
, file
, dir
, (</>)
, and parsePath
.
This ADT allows invalid paths (e.g. paths inside files), but there is no
possible way for such paths to be constructed by user-land code. The only
"invalid path" that may be constructed is using the parentDir'
function, e.g.
parentDir' rootDir
, or by parsing an equivalent string such as /../
,
but such paths are marked as unsandboxed, and may not be rendered to strings
until they are first sandboxed to some directory.
Instances
#runEscaper Source
runEscaper :: Escaper -> String -> String
Given an escaper and a segment to encode, returns the encoded segment.
#posixEscaper Source
posixEscaper :: Escaper
An escaper that removes all slashes, converts ".." into "$dot$dot", and converts "." into "$dot".
#dropExtension Source
dropExtension :: FileName -> FileName
Drops the extension on a file name.
#changeExtension Source
changeExtension :: (String -> String) -> FileName -> FileName
Changes the extension on a file name.
#parentAppend Source
parentAppend :: forall s' s b a. Path a Dir s -> Path Rel b s' -> Path a b Unsandboxed
Ascends into the parent of the specified directory, then descends into the specified path. The result is always unsandboxed because it may escape its previous sandbox.
#isAbsolute Source
isAbsolute :: forall s b a. Path a b s -> Boolean
Determines if this path is absolutely located.
#isRelative Source
isRelative :: forall s b a. Path a b s -> Boolean
Determines if this path is relatively located.
#peel Source
peel :: forall s b a. Path a b s -> Maybe (Tuple (Path a Dir s) (Either DirName FileName))
Peels off the last directory and the terminal file or directory name
from the path. Returns Nothing
if there is no such pair (for example,
if the last path segment is root directory, current directory, or parent
directory).
#unsandbox Source
unsandbox :: forall s b a. Path a b s -> Path a b Unsandboxed
Unsandboxes any path (whether sandboxed or not).
#parentDir' Source
parentDir' :: forall s b a. Path a b s -> Path a Dir Unsandboxed
Creates a path that points to the parent directory of the specified path. This function always unsandboxes the path.
#currentDir Source
currentDir :: forall s. Path Rel Dir s
The "current directory", which can be used to define relatively-located resources.
#canonicalize Source
canonicalize :: forall s b a. Path a b s -> Path a b s
Canonicalizes a path, by reducing things in the form /x/../
to just /x/
.
#unsafePrintPath Source
unsafePrintPath :: forall s b a. Path a b s -> String
#printPath' Source
printPath' :: forall b a. Escaper -> Path a b Sandboxed -> String
Prints a Path
into its canonical String
representation, using the
specified escaper to escape special characters in path segments. For
security reasons, the path must be sandboxed before rendering to string.
#identicalPath Source
identicalPath :: forall s' s b' b a' a. Path a b s -> Path a' b' s' -> Boolean
Determines if two paths have the exact same representation. Note that two paths may represent the same path even if they have different representations!
#sandbox Source
sandbox :: forall s b a. Path a Dir Sandboxed -> Path a b s -> Maybe (Path Rel b Sandboxed)
Attempts to sandbox a path relative to some directory. If successful, the sandboxed
directory will be returned relative to the sandbox directory (although this can easily
be converted into an absolute path using </>
).
This combinator can be used to ensure that paths which originate from user-code cannot access data outside a given directory.
#parsePath Source
parsePath :: forall z. (RelDir Unsandboxed -> z) -> (AbsDir Unsandboxed -> z) -> (RelFile Unsandboxed -> z) -> (AbsFile Unsandboxed -> z) -> String -> z
Parses a canonical String
representation of a path into a Path
value.
Note that in order to be unambiguous, trailing directories should be
marked with a trailing slash character ('/'
).
#parseRelFile Source
parseRelFile :: String -> Maybe (RelFile Unsandboxed)
Attempts to parse a relative file from a string.
#parseAbsFile Source
parseAbsFile :: String -> Maybe (AbsFile Unsandboxed)
Attempts to parse an absolute file from a string.
#parseRelDir Source
parseRelDir :: String -> Maybe (RelDir Unsandboxed)
Attempts to parse a relative directory from a string.
#parseAbsDir Source
parseAbsDir :: String -> Maybe (AbsDir Unsandboxed)
Attempts to parse an absolute directory from a string.
- Modules
- Data.
Path. Pathy