/** * @since 1.0.0 */ import * as Effect from "effect/Effect" import * as Layer from "effect/Layer" import { Path, TypeId } from "effect/platform/Path" import { BadArgument } from "effect/platform/PlatformError" import * as NodePath from "node:path" import * as NodeUrl from "node:url" const fromFileUrl = (url: URL): Effect.Effect => Effect.try({ try: () => NodeUrl.fileURLToPath(url), catch: (cause) => new BadArgument({ module: "Path", method: "fromFileUrl", cause }) }) const toFileUrl = (path: string): Effect.Effect => Effect.try({ try: () => NodeUrl.pathToFileURL(path), catch: (cause) => new BadArgument({ module: "Path", method: "toFileUrl", cause }) }) /** * @since 1.0.0 * @category Layers */ export const layerPosix: Layer.Layer = Layer.succeed(Path)({ [TypeId]: TypeId, ...NodePath.posix, fromFileUrl, toFileUrl }) /** * @since 1.0.0 * @category Layers */ export const layerWin32: Layer.Layer = Layer.succeed(Path)({ [TypeId]: TypeId, ...NodePath.win32, fromFileUrl, toFileUrl }) /** * @since 1.0.0 * @category Layers */ export const layer: Layer.Layer = Layer.succeed(Path)({ [TypeId]: TypeId, ...NodePath, fromFileUrl, toFileUrl })