Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/orouz/route-link
- Owner: orouz
- Created: 2020-10-23T21:00:01.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-07-10T21:30:48.000Z (over 3 years ago)
- Last Synced: 2024-04-23T12:38:31.614Z (7 months ago)
- Language: TypeScript
- Homepage:
- Size: 222 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.MD
Awesome Lists containing this project
README
🔗route-link
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)