/** * @copyright Sister Software * @license MIT * @author Teffen Ellis, et al. */ import type { PluckBasename } from "./basename.js"; import type { PluckDirname } from "./dirname.js"; import type { Join, Resolve } from "./type-utils.js"; /** * A segment accepted when extending a path builder. */ export type PathBuilderSegment = string | number | PathBuilder; type UnwrapPathBuilderSegments = { [K in keyof S]: S[K] extends PathBuilder ? Path : S[K]; } extends infer Segments extends Array ? Segments : never; export type ResolvePathBuilderSegments, Acc extends string> = Segments extends [ infer Head extends string | number, ...infer Tail extends Array ] ? ResolvePathBuilderSegments : Resolve; /** * Type-safe path builder. * * @template S - The type of the path string. */ export interface PathBuilder extends String { /** * Append additional path segments to the current path. */ (...additionalPathSegments: T): PathBuilder, S>>; } /** * A path value supplied when the builder is read. */ export type PathBuilderSource = () => string; /** * Runtime class identifier for the PathBuilder class. * * @internal */ export declare const kPathBuilder: unique symbol; /** * Type-safe path builder, backed by a plain string. * * Unlike a `URL`, a `PathBuilder` never percent-encodes its contents and never truncates at `#` or `?`, so it * round-trips arbitrary POSIX paths verbatim. Extending `String` gives instances the full string method surface for * free. */ export declare class PathBuilder extends String implements PathBuilder { /** * Recognize PathBuilder instances — and their callable proxies — via the {@linkcode kPathBuilder} brand, so * `instanceof` works through the proxy returned by {@linkcode PathBuilder.from}. */ static [Symbol.hasInstance](instance: unknown): boolean; protected constructor(path: S); /** * Get the current path as a string. */ toString(): S; /** * Get the current path as a primitive string. */ valueOf(): S; /** * Return the primitive path used by JSON serialization. */ toJSON(): S; /** * Directory name of a path. Similar to the Unix dirname command. */ dirname(): PathBuilder>; /** * Base name of a path. Similar to the Unix basename command. */ basename(): PluckBasename; get [Symbol.toStringTag](): S; [Symbol.toPrimitive](): S; /** * Normalize a path builder into a type-safe path builder. * * This is typical if your given path is {@linkcode PathBuilderLike} */ static from(pathBuilder: PathBuilder, ...pathSegmentN: Pn): PathBuilder>>; /** * Create a new path builder from a string. */ static from(pathSegment1: P1, ...pathSegmentN: Pn): PathBuilder>>; /** * Normalize a path builder or string into a type-safe path builder. * * This is typical if your given path is {@linkcode PathBuilderLike} */ static from

(pathBuilderLike: P, ...pathSegmentN: Pn): PathBuilder ? T : P, ...Pn], "/">>>; /** * Create a builder whose value is read from a source on demand. * * Descendants retain the source, so a value created before the source changes resolves against the current value when * it is read. */ static fromSource(source: PathBuilderSource): PathBuilder; } /** * Type-safe path builder or string. */ export type PathBuilderLike = string | PathBuilder; /** * Unwraps a path builder or string to its core string type. */ export type UnwrapPathBuilder = T extends PathBuilder ? U : T extends string ? T : never; export default PathBuilder; //# sourceMappingURL=path-builder.d.ts.map