Layer.Layer<Path, never, never>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.
export const const layer: Layer.Layer<Path>const layer: {
build: (memoMap: MemoMap, scope: Scope.Scope) => Effect<Context.Context<Path>, never, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
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.
layer: import LayerLayer.type Layer.Layer = /*unresolved*/ anyLayer<Path> = import LayerLayer.succeed(const Path: Context.Service<Path, Path>namespace Path
const Path: {
key: string;
Service: {
sep: string;
basename: (path: string, suffix?: string) => string;
dirname: (path: string) => string;
extname: (path: string) => string;
format: (pathObject: Partial<Path.Parsed>) => string;
fromFileUrl: (url: URL) => Effect.Effect<string, BadArgument>;
isAbsolute: (path: string) => boolean;
join: (...paths: ReadonlyArray<string>) => string;
normalize: (path: string) => string;
parse: (path: string) => Path.Parsed;
relative: (from: string, to: string) => string;
resolve: (...pathSegments: ReadonlyArray<string>) => string;
toFileUrl: (path: string) => Effect.Effect<URL, BadArgument>;
toNamespacedPath: (path: string) => string;
};
of: (this: void, self: Path) => Path;
context: (self: Path) => Context.Context<Path>;
use: (f: (service: Path) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Path | R>;
useSync: (f: (service: Path) => A) => Effect.Effect<A, never, Path>;
Identifier: Identifier;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
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.
Example (Using path operations)
import { Effect, Path } from "effect"
const program = Effect.gen(function*() {
const path = yield* Path.Path
// Use various path operations
const joined = path.join("home", "user", "documents")
const normalized = path.normalize("./path/../to/file.txt")
const basename = path.basename("/path/to/file.txt")
const dirname = path.dirname("/path/to/file.txt")
const extname = path.extname("file.txt")
const isAbs = path.isAbsolute("/absolute/path")
const parsed = path.parse("/path/to/file.txt")
const relative = path.relative("/from/path", "/to/path")
const resolved = path.resolve("relative", "path")
console.log({
joined,
normalized,
basename,
dirname,
extname,
isAbs,
parsed,
relative,
resolved
})
})
Namespace containing types associated with the Path service.
When to use
Use to reference types associated with path parsing and formatting.
Example (Working with parsed paths)
import { Effect, Path } from "effect"
// Access types and utilities in the Path namespace
const program = Effect.gen(function*() {
const path = yield* Path.Path
// Parse a path and get a Path.Parsed object
const parsed = path.parse("/home/user/file.txt")
// The parsed object conforms to the Path.Parsed interface
const exampleParsed = {
root: "/",
dir: "/home/user",
base: "file.txt",
ext: ".txt",
name: "file"
}
console.log(parsed, exampleParsed)
})
Service tag for accessing the current Path implementation.
When to use
Use when you need path operations supplied by an effect's environment.
Example (Providing a custom Path service)
import { Effect, Layer, Path } from "effect"
// Create a custom path implementation
const customPath: Path.Path = {
[Path.TypeId]: Path.TypeId,
sep: "/",
basename: (path: string, suffix?: string) => {
const base = path.split("/").pop() || ""
return suffix && base.endsWith(suffix)
? base.slice(0, -suffix.length)
: base
},
dirname: (path: string) => path.split("/").slice(0, -1).join("/") || "/",
extname: (path: string) => {
const match = path.match(/\.[^.]*$/)
return match ? match[0] : ""
},
format: (pathObject) => {
const dir = pathObject.dir || ""
const name = pathObject.name || ""
const ext = pathObject.ext || ""
return dir ? `${dir}/${name}${ext}` : `${name}${ext}`
},
fromFileUrl: (url: URL) => Effect.succeed(url.pathname),
isAbsolute: (path: string) => path.startsWith("/"),
join: (...paths: ReadonlyArray<string>) => paths.join("/"),
normalize: (path: string) => path.replace(/\/+/g, "/"),
parse: (path: string) => ({
root: path.startsWith("/") ? "/" : "",
dir: path.split("/").slice(0, -1).join("/") || "/",
base: path.split("/").pop() || "",
ext: path.match(/\.[^.]*$/)?.[0] || "",
name: path.split("/").pop()?.replace(/\.[^.]*$/, "") || ""
}),
relative: (from: string, to: string) => to.replace(from, ""),
resolve: (...pathSegments: ReadonlyArray<string>) => pathSegments.join("/"),
toFileUrl: (path: string) => Effect.succeed(new URL(`file://${path}`)),
toNamespacedPath: (path: string) => path
}
// Provide the path service
const customPathLayer = Layer.succeed(Path.Path)(customPath)
const program = Effect.gen(function*() {
const path = yield* Path.Path
const joined = path.join("home", "user", "file.txt")
console.log(joined) // "home/user/file.txt"
})
// Run with custom path implementation
const result = Effect.provide(program, customPathLayer)
Path)(const posixImpl: Pathconst posixImpl: {
sep: string;
basename: (path: string, suffix?: string) => string;
dirname: (path: string) => string;
extname: (path: string) => string;
format: (pathObject: Partial<Path.Parsed>) => string;
fromFileUrl: (url: URL) => Effect.Effect<string, BadArgument>;
isAbsolute: (path: string) => boolean;
join: (...paths: ReadonlyArray<string>) => string;
normalize: (path: string) => string;
parse: (path: string) => Path.Parsed;
relative: (from: string, to: string) => string;
resolve: (...pathSegments: ReadonlyArray<string>) => string;
toFileUrl: (path: string) => Effect.Effect<URL, BadArgument>;
toNamespacedPath: (path: string) => string;
}
posixImpl)