Build URLs with confidence. Path parameters are inferred from your template strings, and extra params become query strings automatically.
$ npm install @bearstudio/lunalinkDemo
const path = "/contacts/:id"; // Type is inferred as { id: string } const url = lunalink(path, { id: "4F82CDA2-B869-48A2-A829-F161DB6A94DA", });
// Extra params are automatically added as query strings const url = lunalink("/contacts/:id", { id: "4F82CDA2", search: "FirstName", page: "1", });
// Multiple path parameters, all type-checked const url = lunalink("/api/users/:userId/posts/:postId", { userId: "42", postId: "7", });
Features
Path parameters are extracted from your template string at the type level. Miss a param and TypeScript will tell you.
Any extra params that don't match a path placeholder are automatically appended as query string parameters.
Tiny footprint with zero unnecessary overhead. Ships ESM and CJS so it works everywhere.
Pass a baseURL in the config to automatically join your API root with the constructed path.
Bring your own encodeURIComponent function for full control over how parameters are escaped.
Supports params separated by slashes, dots, and optional trailing markers. Covers real-world URL patterns.