API reference

yatta/path

Path templates: one parser for the client, the router and the handler.

10 exported symbols and 4 members, read from src/types/path.ts.

Construct

buildPathFrom

function

Builds a URL path from a template and its parameters.

A parameter with no value is omitted when it is optional; a required one is an error, because sending the string "undefined" produces a request that reaches a handler as a real segment.

buildPathFrom(parsed: ParsedPath, params?: Record<string, unknown>): string

bySpecificity

function

Orders templates so the most specific one is tried first.

`/users/new` must be matched before `/users/:id`, or a create endpoint silently becomes a fetch of a user whose id is the literal string "new". A static segment beats a parameter at the same position; a wildcard loses to both. Stable for templates that are equally specific, so declaration order decides between two routes that cannot both match.

bySpecificity(a: ParsedPath, b: ParsedPath): number

extractParams

function

Reads the parameters out of a request path.

extractParams(parsed: ParsedPath, path: string): Record<string, string>

matchesPath

function

Matches a request path against a parsed template.

An optional parameter may be absent, and a wildcard absorbs whatever is left.

matchesPath(parsed: ParsedPath, path: string): boolean

parseTemplate

function

Parses a path template.

parseTemplate(template: string): ParsedPath

readQuery

function

Splits a query string into scalars, or arrays where a key really did repeat.

readQuery(url: string): Record<string, unknown>

stripBase

function

Strips a mount point from a path, when the platform does not include it.

stripBase(path: string, basePath: string | undefined): string

PathTemplateError

class
class PathTemplateError extends Error

Types

ParsedPath

interface

A template, parsed.

interface ParsedPath

4 members

  • templateproperty
    template: string
  • segmentsproperty
    segments: readonly Segment[]
  • wildcardproperty
    wildcard: boolean

    True when the last segment is a wildcard, which may contain slashes.

  • arityproperty
    arity: number

    Required segment count, for matching a path with no wildcard.

Segment

type

One segment of a parsed template.

type Segment = { readonly kind: "static"; readonly value: string; } | { readonly kind: "param"; readonly name: string; readonly optional: boolean; } | { readonly kind: "wildcard"; readonly name: string; }
Tip
Most of the types above are inferred. You rarely import AuthConfig or JobPayload — declaring your schema once is enough for the rest to follow. See Typed keys.