0.1.9 • Published 8 months ago

@mpen/rerouter v0.1.9

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

@mpen/rerouter

An implementation of RFC 6570: URI Template.

Installation

bun add @mpen/rerouter

API

const templ = new UriTemplate('/query{?firstName,lastName}')
console.log(templ.match('/query?firstName=Bj%c3%b6rk&lastName=Gu%c3%b0mundsd%c3%b3ttir'))
// {
//   score: 7,
//   params: {
//     firstName: "Björk",
//     lastName: "Guðmundsdóttir"
//   }
// }
console.log(templ.expand({firstName: 'Mark', lastName: 'Penner'}))
// /query?firstName=Mark&lastName=Penner

That's it. That's the whole API. 2 methods.

It's been tested against https://github.com/uri-templates/uritemplate-test and all 157 tests pass.

The score is still experimental. The idea is that you can run a URL against multiple templates and if multiple match, you should use the one with the highest score. Higher score means more matching parts, i.e. more specific match.

0.1.9

8 months ago

0.1.7

8 months ago

0.1.5

8 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago