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

DSL overview

DSL for subset of path-to-regexp syntax

Added in v1.0.0


Table of contents


Constructor

oneOrMore

one or more path parts will be matched to this param

Signature

export declare const oneOrMore: <A extends string>(param: A) => `${A}+`

Added in v1.0.0

optional

Signature

export declare const optional: <A extends string>(param: A) => `${A}?`

Added in v1.0.0

param

Signature

export declare const param: <A extends string>(param: A) => `:${A}`

Added in v1.0.0

paramWithOptions

Signature

export declare const paramWithOptions: <const A extends string, Options extends readonly string[]>(
  param: A,
  ...options: Options
) => `:${A}(${S.Join<Options, "|">})`

Added in v1.0.0

prefix

Signature

export declare const prefix: <P extends string, A extends string>(prefix: P, param: A) => `{${P}${A}}`

Added in v1.0.0

queryParam

Construct query params

Signature

export declare const queryParam: <K extends string, V extends string>(key: K, value: V) => QueryParam<K, V>

Added in v1.0.0

queryParams

Signature

export declare const queryParams: <P extends readonly [any, ...any[]]>(...params: P) => QueryParams<P, "">

Added in v1.0.0

unnamed

Signature

export declare const unnamed: "(.*)"

Added in v1.0.0

zeroOrMore

Signature

export declare const zeroOrMore: <A extends string>(param: A) => `${A}*`

Added in v1.0.0

Model

OneOrMore (type alias)

Signature

export type OneOrMore<A extends string> = `${A}+`

Added in v1.0.0

Optional (type alias)

Template for optional path parts

Signature

export type Optional<A extends string> = `${A}?`

Added in v1.0.0

Param (type alias)

Template for parameters

Signature

export type Param<A extends string> = `:${A}`

Added in v1.0.0

ParamWithOptions (type alias)

Template for parameters

Signature

export type ParamWithOptions<A extends string, Options extends ReadonlyArray<string>> = `:${A}(${S.Join<Options, "|">})`

Added in v1.0.0

Prefix (type alias)

Construct a custom prefix

Signature

export type Prefix<P extends string, A extends string> = `{${P}${A}}`

Added in v1.0.0

QueryParam (type alias)

Construct query params

Signature

export type QueryParam<K extends string, V extends string> = `` extends V ? K : `${K}=${V}`

Added in v1.0.0

QueryParams (type alias)

Creates the path-to-regexp syntax for query parameters

Signature

export type QueryParams<Q extends ReadonlyArray<QueryParam<any, any>>, R extends string = ``> = Q extends readonly [
  infer Head extends string,
  ...infer Tail extends ReadonlyArray<QueryParam<any, any>>
]
  ? QueryParams<Tail, `` extends R ? `\\?${Head}` : `${R}&${Head}`>
  : R

Added in v1.0.0

Unnamed (type alias)

Signature

export type Unnamed = typeof unnamed

Added in v1.0.0

ZeroOrMore (type alias)

zero or more path parts will be matched to this param

Signature

export type ZeroOrMore<A extends string> = `${A}*`

Added in v1.0.0