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
functionBuilds 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>): stringbySpecificity
functionOrders 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): numberextractParams
functionReads the parameters out of a request path.
extractParams(parsed: ParsedPath, path: string): Record<string, string>matchesPath
functionMatches 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): booleanparseTemplate
functionParses a path template.
parseTemplate(template: string): ParsedPathreadQuery
functionSplits a query string into scalars, or arrays where a key really did repeat.
readQuery(url: string): Record<string, unknown>stripBase
functionStrips a mount point from a path, when the platform does not include it.
stripBase(path: string, basePath: string | undefined): stringPathTemplateError
classclass PathTemplateError extends ErrorTypes
ParsedPath
interfaceA template, parsed.
interface ParsedPath4 members
templatepropertytemplate: stringsegmentspropertysegments: readonly Segment[]wildcardpropertywildcard: booleanTrue when the last segment is a wildcard, which may contain slashes.
aritypropertyarity: numberRequired segment count, for matching a path with no wildcard.
Segment
typeOne 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; }AuthConfig or JobPayload — declaring your schema once is enough for the rest to follow. See Typed keys.