Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/orouz/route-link

a utility for constructing type-safe URLs
https://github.com/orouz/route-link

Last synced: 1 day ago
JSON representation

a utility for constructing type-safe URLs

Awesome Lists containing this project

README

        


🔗

route-link




npm version



License: MIT

utilities for constructing type-safe URLs


## **Install**

`npm i route-link`


## **Example Usage**

```typescript
import { route, extend } from "route-link";

const posts = route("/posts");
const post = extend(posts, '/:post_id')

// generate type safe links
posts.link() // /posts
post.link({ post_id: "1" }); // /posts/1

// match URLs to path
post.match(post.link({ post_id: "1" })) // { post_id: "1" };
post.match("/foo")) // false

// use route path

```

as a convivnce, `link` and `match` are also exported separately

## Credits

- [@danvk](https://github.com/danvk) for the [type](https://twitter.com/danvdk/status/1301707026507198464?lang=en) [wizardy](https://stackoverflow.com/questions/51488717/declaring-dependent-argument-types-for-optional-arguments-with-conditional-types/64796265#64796265)