Pathy
- Package
- purescript-pathy
- Repository
- purescript-contrib/purescript-pathy
Re-exports from Pathy.Name
#splitName Source
splitName :: forall n. Name n -> { ext :: Maybe NonEmptyString, name :: NonEmptyString }Splits Name in name and extension part.
splitName (Name ".foo") == { name: ".foo", extension: Nothing }
splitName (Name "foo.") == { name: "foo.", extension: Nothing }
splitName (Name "foo") == { name: "foo", extension: Nothing }
splitName (Name ".") == { name: ".", extension: Nothing }
splitName (Name "foo.baz") == { name: "foo", extension: Just "baz" }
Note, in real code all strings from this examples would be NonEmptyString.
Also for any Name this property holds:
joinName <<< splitName = id
see joinName.
#joinName Source
joinName :: forall n. { ext :: Maybe NonEmptyString, name :: NonEmptyString } -> Name nJoins name and extension part into one Name.
Also for any Name this property holds:
joinName <<< splitName = id
see splitName.
#extension Source
extension :: forall n. Name n -> Maybe NonEmptyStringRetrieves the extension of a name. also see splitName
extension (Name ".foo") == Nothing
extension (Name "foo.") == Nothing
extension (Name ".") == Nothing
extension (Name "foo.baz") == Just "baz"
Note, in real code all strings from this examples would be NonEmptyString.
#alterExtension Source
alterExtension :: forall n. (Maybe NonEmptyString -> Maybe NonEmptyString) -> Name n -> Name nAlters an extension of a name. This allows extensions to be added, removed,
or modified. see splitName and joinName
for how a Name is split into name and extention part and joined back
into a Name.
Also for any Name this property holds:
alterExtension id = id
Re-exports from Pathy.Parser
#posixParser Source
posixParser :: ParserA parser for POSIX paths.
#parseRelFile Source
parseRelFile :: Parser -> String -> Maybe RelFileAttempts to parse a relative file.
#parseRelDir Source
parseRelDir :: Parser -> String -> Maybe RelDirAttempts to parse a relative directory.
#parseAbsFile Source
parseAbsFile :: Parser -> String -> Maybe AbsFileAttempts to parse an absolute file.
#parseAbsDir Source
parseAbsDir :: Parser -> String -> Maybe AbsDirAttempts to parse an absolute directory.
Re-exports from Pathy.Path
#Path Source
data Path :: RelOrAbs -> DirOrFile -> Typedata Path a b
A type that describes a Path. All flavors of paths are described by this type, whether they are absolute or relative paths and whether they refer to files or directories.
- The type parameter
adescribes whether the path isRelorAbs. - The type parameter
bdescribes whether the path isFileorDir.
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.
Instances
Eq (Path a b)Ord (Path a b)(IsRelOrAbs a, IsDirOrFile b) => Show (Path a b)
#setExtension Source
setExtension :: forall a b. Path a b -> String -> Path a bSets the extension on the terminal segment of a path. If the path is
rootDir / currentDir or a relative path that is ascending (../) this
will have no effect.
file "image" <.> "png"
See splitName and alterExtension
fore more examples.
#renameTraverse Source
renameTraverse :: forall f a b. Applicative f => (Name b -> f (Name b)) -> Path a b -> f (Path a b)Attempts to rename the terminal segment of a path using a function that
returns the result in some Applicative. If the path is rootDir /
currentDir or a relative path that is ascending (../) this will
have no effect.
#parentAppend Source
parentAppend :: forall a b. IsRelOrAbs a => Path a Dir -> Path Rel b -> Path a bAscends into the parent of the specified directory, then descends into the specified path.
rootDir </> dir "foo" <..> dir "bar" = rootDir </> dir "bar"
#name Source
name :: forall a b. IsRelOrAbs a => IsDirOrFile b => Path a b -> Maybe (Name b)Retrieves the name of the terminal segment in a path. Returns Nothing if
the path is rootDir / currentDir or some parentOf p.
#in' Source
in' :: forall a. Name a -> Path Rel aCreates a path which points to a relative directory or file of the specified name.
In most cases dir' or file' should be used instead,
but it's still there in case the segment type is going to be determined based
on some type variable.
p == maybe p (\(Tuple r n) -> r </> in' n) (peel p)
#foldPath Source
foldPath :: forall a b r. r -> (Path Rel Dir -> r) -> (Path a Dir -> Name b -> r) -> Path a b -> rA fold over Paths. Since Path has private constructors, this allows for
functions to be written over its constructors, similar to a total pattern
match.
- The first argument is the value to return for the
currentDir/rootDirat the base of the path. - The second argument is a function for handling a step into the parent
directory of the path it receives (eliminates
parentOf). - The third argument is a function representing a file or directory within
the directory of the path it receives (eliminates
extendPath).
#extendPath Source
extendPath :: forall a b. Path a Dir -> Name b -> Path a bExtends a path with a file or directory under the current path.
#currentDir Source
currentDir :: Path Rel DirThe "current directory", which can be used to define relatively-located resources.
#appendPath Source
appendPath :: forall a b. IsRelOrAbs a => Path a Dir -> Path Rel b -> Path a bGiven a directory path, appends a relative path to extend the original path.
Re-exports from Pathy.Phantom
#IsDirOrFile Source
class IsDirOrFile :: DirOrFile -> Constraintclass IsDirOrFile b where
A class that enables writing operations that abstract over DirOrFile.
The provided onDirOrFile function folds over a value indexed by
DirOrFile to produce a new result, passing proof/coercion functions to
allow the inner functions to unify their return types if remapping.
Members
onDirOrFile :: forall f r. ((f Dir -> f b) -> f Dir -> r) -> ((f File -> f b) -> f File -> r) -> f b -> r
Instances
#IsRelOrAbs Source
class IsRelOrAbs :: RelOrAbs -> Constraintclass IsRelOrAbs a where
A class that enables writing operations that abstract over RelOrAbs.
The provided onRelOrAbs function folds over a value indexed by
RelOrAbs to produce a new result, passing proof/coercion functions to
allow the inner functions to unify their return types if remapping.
Members
onRelOrAbs :: forall (f :: RelOrAbs -> DirOrFile -> Type) b r. ((f Rel b -> f a b) -> f Rel b -> r) -> ((f Abs b -> f a b) -> f Abs b -> r) -> f a b -> r
Instances
#foldRelOrAbs Source
foldRelOrAbs :: forall f a b r. IsRelOrAbs a => (f Rel b -> r) -> (f Abs b -> r) -> f a b -> rFolds over a value that uses RelOrAbs to produce a new result.
#foldDirOrFile Source
foldDirOrFile :: forall f b r. IsDirOrFile b => (f Dir -> r) -> (f File -> r) -> f b -> rFolds over a value that uses DirOrFile to produce a new result.
Re-exports from Pathy.Printer
#Printer Source
type Printer = { current :: NonEmptyString, escaper :: Escaper, root :: Maybe NonEmptyString -> String, sep :: NonEmptyString, up :: NonEmptyString }A Printer defines options for printing paths.
rootis a function used to construct the initial segment of paths.currentis a representation of the current directory.upis a representation of going up to the parent directory.sepis the string to separate path segments by.escaperspecified how to deal with printing reserved names and characters.
#Escaper Source
newtype EscaperAn Escaper encodes segments or characters which have reserved meaning
within names in a path.
Constructors
Instances
#windowsPrinter Source
windowsPrinter :: PrinterA printer for Windows paths.
#unsafePrintPath Source
unsafePrintPath :: forall a b. IsRelOrAbs a => IsDirOrFile b => Printer -> SandboxedPath a b -> StringPrints a SandboxedPath into its canonical String representation, using
the specified printer. This will print a relative path if b ~ Rel, which
depending on how the resulting string is used, may be unsafe.
#printPath Source
printPath :: forall a b. IsRelOrAbs a => IsDirOrFile b => Printer -> SandboxedPath a b -> StringPrints a SandboxedPath into its canonical String representation, using
the specified printer. The printed path will always be absolute, as this
is the only way to ensure the path is safely referring to the intended
location.
#posixPrinter Source
posixPrinter :: PrinterA printer for POSIX paths.
#debugPrintPath Source
debugPrintPath :: forall a b. Warn (Text "debugPrintPath usage") => IsRelOrAbs a => IsDirOrFile b => Printer -> Path a b -> StringPrints a path exactly according to its representation. This should only be used for debug purposes. Using this function will raise a warning at compile time as a reminder!
Re-exports from Pathy.Sandboxed
#SandboxedPath Source
data SandboxedPath :: RelOrAbs -> DirOrFile -> Typedata SandboxedPath a b
The type for paths that have been sandboxed.
Instances
(IsRelOrAbs a, IsDirOrFile b) => Eq (SandboxedPath a b)(IsRelOrAbs a, IsDirOrFile b) => Ord (SandboxedPath a b)(IsRelOrAbs a, IsDirOrFile b) => Show (SandboxedPath a b)
#unsandbox Source
unsandbox :: forall a b. SandboxedPath a b -> Path a bExtracts the original path from a SandboxedPath.
#sandboxRoot Source
sandboxRoot :: forall a b. SandboxedPath a b -> Path Abs DirReturns the location a SandboxedPath was sandboxed to.
#sandboxAny Source
sandboxAny :: forall a b. Path a b -> SandboxedPath a bSandboxes any path to /.
This should only be used for situations where a path is already constrained
within a system so that access to / is safe - for instance, in URIs.
#sandbox Source
sandbox :: forall a b. IsRelOrAbs a => Path Abs Dir -> Path a b -> Maybe (SandboxedPath a b)Attempts to sandbox a path relative to an absolute directory ("sandbox
root"). If the Path a b escapes the sandbox root Nothing will be
returned.