dillonkearns/elm-pages/12.1.2

NOTE: the latest version is 12.3.0

FilePath

Cross-platform file path utilities for BackendTask.File and Pages.Script.

The representation is opaque so we can evolve path behavior over time without exposing implementation details.

Opaque file path type.

fromString : String -> FilePath

Build a path from a string. Accepts both / and \\ separators.

This normalizes the path to a stable representation:

  • Converts \\ to /
  • Collapses duplicate separators
  • Removes . segments
  • Resolves .. segments when possible
  • Removes trailing separators (except for roots)

It accepts both relative and absolute paths.

relative : List String -> FilePath

Build a relative path from segments.

FilePath.relative [ "src", "Main.elm" ]
    |> FilePath.toString
--> "src/Main.elm"
absolute : List String -> FilePath

Build an absolute path from segments.

FilePath.absolute [ "usr", "bin" ]
    |> FilePath.toString
--> "/usr/bin"
toString : FilePath -> String

Convert a path to a string. Uses / separators.

segments : FilePath -> List String

Return path segments without root markers.

Append a path to a base path.

If nextPath has a root marker (absolute path, UNC path, or drive prefix), it replaces the base path.

Join many paths from left to right.

Parent directory of a path.

filename : FilePath -> Maybe String

The final path segment, if any.

Filename without extension.

extension : FilePath -> Maybe String

File extension without the dot.

Path to targetPath relative to basePath.

Returns Nothing when roots differ.

resolve : FilePath -> BackendTask FatalError FilePath

Resolve a file path to an absolute path using the OS-aware path.resolve from Node.js.

Relative paths are resolved against the current working directory.

import BackendTask exposing (BackendTask)
import FatalError exposing (FatalError)
import FilePath


resolveExample : BackendTask FatalError FilePath
resolveExample =
    FilePath.fromString "src/Main.elm"
        |> FilePath.resolve