constmatchPattern=pathPattern("/api/:version{v1|v2}/users/:id");constresult=matchPattern("/api/v1/users/123");typeResult=|undefined|{version: "v1"|"v2";id: string;};constresult={id: "123",version: "v1"};pathPattern matches the path only, and ignores the protocol and host entirely:
constmatchPattern=pathPattern("/:workspaceId/task/:taskId");matchPattern("/ws1/task/t1");// {...}matchPattern("https://anything.com/ws1/task/t1");// {...}urlPattern matches the whole url, and requires a protocol and a host:
constmatchPattern=urlPattern("miko://:workspaceId/task/:taskId");matchPattern("miko://ws1/task/t1");// {...}matchPattern("https://evil.com/ws1/task/t1");// undefinedReach for urlPattern whenever the origin is part of what you are asserting — deep links, webhooks, anything where a url from somewhere else must not be mistaken for one of yours.
npm install @monstermann/url-patternpnpm add @monstermann/url-patternyarn add @monstermann/url-patternbun add @monstermann/url-pattern