/** * @copyright Sister Software * @license MIT * @author Teffen Ellis, et al. */ import type { PathBuilder, UnwrapPathBuilder } from "./path-builder.js"; import type { IsAbsolute, Join, Resolve, Split } from "./type-utils.js"; /** * Drop the segments two absolute paths share, from the left. */ type StripCommonPrefix = A extends [infer AH, ...infer AT extends string[]] ? B extends [infer BH, ...infer BT extends string[]] ? [AH, BH] extends [BH, AH] ? StripCommonPrefix : [A, B] : [A, B] : [A, B]; /** * One `..` per segment. */ type ParentSteps = Segments extends [ infer _, ...infer Rest extends string[] ] ? ParentSteps : Steps; /** * The relative path from `From` to `To`, e.g. `Relative<"/a/b", "/a/c/d">` is `"../c/d"`. Only two absolute paths have * a literal answer — a relative input is resolved against the current working directory at runtime, which the type * cannot know — so anything else is `string`. */ export type Relative = string extends From | To ? string : [IsAbsolute, IsAbsolute] extends [true, true] ? StripCommonPrefix, "/">, Split, "/">> extends [ infer F extends string[], infer T extends string[] ] ? Join<[...ParentSteps, ...T], "/"> : never : string; /** * The relative path from `from` to `to`. Similar to `node:path`'s `relative`: an empty string when both name the same * location, and `..` steps up out of `from` as far as the paths diverge. * * @returns The relative path, typed as its literal when both inputs are absolute literals. * @throws {TypeError} If either path is not a string or {@linkcode PathBuilder}. */ export declare function relative(from: From, to: To): Relative, UnwrapPathBuilder>; export default relative; //# sourceMappingURL=relative.d.ts.map