Skip to main content

Function: parseMatchKind()

parseMatchKind(route): "exact" | "param" | "prefix"

Defined in: packages/core/src/parseMatchKind.ts:33

Derives the matchKind for a route pointer. An ArtifactStore implementation calls this inside publish and puts the result on the pointer it writes, so the caller of publish never supplies one.

Parameters

route

string

The route the pointer will address: rooted at /, no trailing slash except at the root itself, [bracketed] param segments, and * only as the final segment.

Returns

"exact" | "param" | "prefix"

"prefix" for a route ending in /*, "param" for one carrying a [bracketed] segment, and "exact" for anything else — / included.

Throws

NubbinError with code NubbinIssueCode.InvalidRoute when the route is not addressable: it does not start at /, it trails a slash, a segment is empty or carries a character a URL path cannot, a bracketed segment names nothing, or * sits mid-route. The at on the issue is the offending route.

Example

import { parseMatchKind } from "@nubbin/core";

parseMatchKind("/about"); // "exact"
parseMatchKind("/guides/[city]"); // "param"
parseMatchKind("/collections/*"); // "prefix"
parseMatchKind("pricing"); // throws NubbinError — a route starts at the root