Skip to content

Path

Provides path operations through the Effect environment.

The Path service works with file system paths without tying code to one concrete platform module. It exposes common operations such as joining, normalizing, parsing, formatting, resolving, and converting paths to or from file URLs. This module includes the service interface, parsed path type, service tag, runtime marker, and built-in POSIX path layer.

5 exports Added in v4.0.0 Source

Layers

layer

Added in v4.0.0 Source

Layer that provides the built-in POSIX Path implementation.

When to use

Use when you need an effect that requires the Path service to run with the built-in POSIX path implementation.

Details

The layer provides a static service whose separator is / and whose operations use POSIX path semantics.

See

  • Path for accessing the Path service from an effect

Signature

declare const layer: Layer.Layer<Path>;

Other

Path

Added in v4.0.0 Source

Namespace containing types associated with the Path service.

When to use

Use to reference types associated with path parsing and formatting.

Services

Path

Added in v4.0.0 Source

Service tag for accessing the current Path implementation.

When to use

Use when you need path operations supplied by an effect's environment.

Signature

declare const Path: Service<Path, Path>;

Path interface

Added in v4.0.0 Source

Defines the service interface for platform-specific path manipulation.

When to use

Use to depend on path operations through the Effect environment instead of a concrete host path module.

Details

The service exposes operations for joining, normalizing, parsing, formatting, and converting file system paths. URL conversion methods return Effects because invalid file URLs or paths can fail with BadArgument.

Signature

interface Path {
  readonly "~effect/platform/Path": "~effect/platform/Path";
  readonly basename: (path: string, suffix?: string) => string;
  readonly dirname: (path: string) => string;
  readonly extname: (path: string) => string;
  readonly format: (pathObject: Partial<Path.Parsed>) => string;
  readonly fromFileUrl: (url: URL) => Effect<string, BadArgument>;
  readonly isAbsolute: (path: string) => boolean;
  readonly join: (...paths: readonly Array<string>) => string;
  readonly normalize: (path: string) => string;
  readonly parse: (path: string) => Parsed;
  readonly relative: (from: string, to: string) => string;
  readonly resolve: (...pathSegments: readonly Array<string>) => string;
  readonly sep: string;
  readonly toFileUrl: (path: string) => Effect<URL, BadArgument>;
  readonly toNamespacedPath: (path: string) => string;
}

Type IDs

TypeId

Added in v4.0.0 Source

Runtime type identifier used to mark implementations of the Path service.

Details

The marker is the exact string stored on Path service implementations. Most code should depend on the Path service instead of inspecting this value directly.

See

  • layer for the built-in POSIX Path service layer

Signature

declare const TypeId: "~effect/platform/Path";