@fedify/uri-template
v2.0.0-pr.475.1
Published
URI Template (RFC 6570) utilities for Fedify
Readme
@fedify/uri-template: RFC 6570 URI Template implementation
This package provides RFC 6570 fully compliant URI template expansion and
pattern matching library. Supports symmetric matching where
expand(match(url)) and match(expand(vars)) behave predictably.
Features
- Full RFC 6570 Level 4 support: Handles all operators and modifiers
(explode
*, prefix:n) - Symmetric pattern matching:
opaque: byte-for-byte exact round-tripscooked: human-readable decoded valueslossless: preserves both raw and decoded forms
- Strict percent-encoding validation: Prevents malformed sequences
(
%GZ, etc.) - Deterministic expansion: Correctly handles undefined/empty values per RFC rules
Installation
deno add jsr:@fedify/uri-template # Deno
npm add @fedify/uri-template # npm
pnpm add @fedify/uri-template # pnpm
yarn add @fedify/uri-template # Yarn
bun add @fedify/uri-template # BunUsage
import { compile } from "@fedify/uri-template";
const tmpl = compile("/repos{/owner,repo}{?q,lang}");
// Expansion
const url = tmpl.expand({ owner: "foo", repo: "hello/world", q: "a b" });
// => "/repos/foo/hello%2Fworld?q=a%20b"
// Matching
const result = tmpl.match("/repos/foo/hello%2Fworld?q=a%20b", {
encoding: "cooked"
});
// => { owner: "foo", repo: "hello/world", q: "a b" }Matching options:
encoding:"opaque"(default, preserves raw) |"cooked"(decoded) |"lossless"(both)strict:true(default, strict) |false(lenient parsing)
Documentation
For detailed implementation details, see specification.md.
