import { op_path_platform } from "ext:core/ops"; import { posix as posixNamespace, win32 as win32Namespace } from "./api.js"; export interface ParsedPath { root: string; dir: string; base: string; name: string; ext: string; } export interface PathObject { dir?: string; root?: string; base?: string; name?: string; ext?: string; } /** Lexical path operations with one fixed separator flavor, plus file URL conversion for that flavor. */ export interface Path { join(...paths: string[]): string; resolve(...paths: string[]): string; normalize(path: string): string; relative(from: string, to: string): string; dirname(path: string): string; basename(path: string, suffix?: string): string; extname(path: string): string; isAbsolute(path: string): boolean; parse(path: string): ParsedPath; format(pathObject: PathObject): string; toNamespacedPath(path: string): string; readonly sep: string; readonly delimiter: string; fromFileUrl(url: URL | string): string; toFileUrl(path: string): URL; } /** Explicit POSIX semantics on any host. */ export const posix: Path = posixNamespace; /** Explicit Windows semantics on any host. */ export const win32: Path = win32Namespace; const native = op_path_platform() === "win32" ? win32 : posix; /** Joins segments with the native separator, then normalizes; `""` segments are skipped. */ export const join: (...paths: string[]) => string = native.join; /** Resolves segments right to left, consulting the working directory only for relative, root-relative, or drive-relative input; fully qualified inputs need no read grant. */ export const resolve: (...paths: string[]) => string = native.resolve; export const normalize: (path: string) => string = native.normalize; /** Lexical path from `from` to `to`; fully qualified pairs need no read grant. */ export const relative: (from: string, to: string) => string = native.relative; export const dirname: (path: string) => string = native.dirname; export const basename: (path: string, suffix?: string) => string = native.basename; export const extname: (path: string) => string = native.extname; export const isAbsolute: (path: string) => boolean = native.isAbsolute; export const parse: (path: string) => ParsedPath = native.parse; export const format: (pathObject: PathObject) => string = native.format; export const toNamespacedPath: (path: string) => string = native.toNamespacedPath; export const sep: string = native.sep; export const delimiter: string = native.delimiter; /** Converts an absolute `file:` URL to a path; rejects queries, fragments, and encoded separators. Needs no permissions. */ export const fromFileUrl: (url: URL | string) => string = native.fromFileUrl; /** Converts an absolute path to a `file:` URL; never consults the working directory. Needs no permissions. */ export const toFileUrl: (path: string) => URL = native.toFileUrl;