/** * @file Pure POSIX-like path helpers. * * OPFS has no symbolic links, therefore `.` and `..` can be resolved * lexically without touching the file system. * * @remarks * The public API mirrors `node:path` from the Node.js project, used here * as the reference specification. Node.js is distributed under the MIT * license. * * @see {@link https://nodejs.org/api/path.html} */ import { ROOT_PATH } from './constants.mjs'; export type ParsedPath = { /** * Root of the path. Always `/`. */ root: string; /** * Directory of the path. */ dir: string; /** * Base name, including the extension. */ base: string; /** * Extension, including the leading dot. */ ext: string; /** * Base name, without the extension. */ name: string; }; export type PathObject = { /** * Root of the path. */ root?: string; /** * Directory of the path. */ dir?: string; /** * Base name, including the extension. */ base?: string; /** * Extension, including the leading dot. */ ext?: string; /** * Base name, without the extension. */ name?: string; }; /** * @typedef {Object} ParsedPath * @property {string} root Root of the path. Always `/`. * @property {string} dir Directory of the path. * @property {string} base Base name, including the extension. * @property {string} ext Extension, including the leading dot. * @property {string} name Base name, without the extension. */ /** * @typedef {Object} PathObject * @property {string} [root] Root of the path. * @property {string} [dir] Directory of the path. * @property {string} [base] Base name, including the extension. * @property {string} [ext] Extension, including the leading dot. * @property {string} [name] Base name, without the extension. */ /** * Platform-specific path segment separator. Always `/` in the browser. * * @type {string} */ export declare const sep: string; /** * Platform-specific list separator, as used by `PATH`-like variables. * * @type {string} */ export declare const delimiter: string; /** * Splits a POSIX-like path into normalised segments. * * @param {string} targetPath Path to normalise. * @returns {string[]} The normalised segments, without empty entries. */ export declare const toSegments: (targetPath: string) => string[]; /** * Rebuilds an absolute path from normalised segments. * * @param {string[]} segments Normalised segments. * @returns {string} An absolute path starting with `/`. */ export declare const toAbsolutePath: (segments: string[]) => string; /** * Normalises a path. * * @param {string} targetPath Path to normalise. * @returns {string} The normalised absolute path. */ export declare const normalize: (targetPath: string) => string; /** * Joins path fragments and normalises the result. * * @param {string[]} parts Path fragments. * @returns {string} The joined absolute path. */ export declare const join: (...parts: string[]) => string; /** * Returns the parent directory of a path. * * @param {string} targetPath Source path. * @returns {string} The parent directory. */ export declare const dirname: (targetPath: string) => string; /** * Returns the last segment of a path. * * @param {string} targetPath Source path. * @param {string} [extension] Extension removed from the result. * @returns {string} The base name. */ export declare const basename: (targetPath: string, extension?: string) => string; /** * Returns the extension of a path, including the leading dot. * * @param {string} targetPath Source path. * @returns {string} The extension, or an empty string. */ export declare const extname: (targetPath: string) => string; /** * Reports whether a path is absolute. * * @param {string} targetPath Source path. * @returns {boolean} `true` when the path starts with a slash. */ export declare const isAbsolute: (targetPath: string) => boolean; /** * Resolves a sequence of path fragments against a working directory. * * @param {string} cwd Working directory used for relative fragments. * @param {string[]} parts Path fragments. * @returns {string} The resolved absolute path. */ export declare const resolve: (cwd: string, ...parts: string[]) => string; /** * Parses a path into its structural components. * * @param {string} targetPath Source path. * @returns {ParsedPath} The parsed components. */ export declare const parse: (targetPath: string) => ParsedPath; /** * Builds a path from its structural components. * * @param {PathObject} pathObject Components to serialise. * @returns {string} The normalised absolute path. * @throws {TypeError} When `pathObject` is not a plain object. */ export declare const format: (pathObject: PathObject) => string; /** * Computes the relative path from one location to another. * * @param {string} from Source path. * @param {string} to Destination path. * @returns {string} The relative path, or an empty string when both are equal. */ export declare const relative: (from: string, to: string) => string; export { ROOT_PATH }; //# sourceMappingURL=path.d.mts.map