Skip to main content Link Search Menu Expand Document (external link)

PathJoin overview

Type-level path joining

Added in v1.0.0


Table of contents


Combinator

formatPart

Formats a piece of a path

Signature

export declare const formatPart: (part: string) => string

Added in v1.0.0

pathJoin

Join together path parts

Signature

export declare const pathJoin: <P extends readonly string[]>(...parts: P) => PathJoin<P>

Added in v1.0.0

removeLeadingSlash

Signature

export declare const removeLeadingSlash: <A extends string>(a: A) => RemoveLeadingSlash<A>

Added in v1.0.0

removeTrailingSlash

Signature

export declare const removeTrailingSlash: <A extends string>(a: A) => RemoveTrailingSlash<A>

Added in v1.0.0

Type-level

FormatPart (type alias)

Signature

export type FormatPart<P extends string> = `` extends P
  ? P
  : RemoveSlash<P> extends `\\?${infer _}`
    ? RemoveSlash<P>
    : P extends `{${infer _}`
      ? P
      : `/${RemoveSlash<P>}`

Added in v1.0.0

PathJoin (type alias)

Composes other path parts into a single path

Signature

export type PathJoin<A> = A extends readonly [infer Head extends string, ...infer Tail extends ReadonlyArray<string>]
  ? `${FormatPart<Head>}${PathJoin<Tail>}`
  : ``

Added in v1.0.0

RemoveLeadingSlash (type alias)

Remove forward slashes prefixes recursively

Signature

export type RemoveLeadingSlash<A> = A extends `/${infer R}` ? RemoveLeadingSlash<R> : A

Added in v1.0.0

RemoveTrailingSlash (type alias)

Remove forward slashes postfixes recursively

Signature

export type RemoveTrailingSlash<A> = A extends `${infer R}/` ? RemoveTrailingSlash<R> : A

Added in v1.0.0