@mpen/rerouter
TypeScript icon, indicating that this package has built-in type declarations

0.1.9 • Public • Published

@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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.9
    1
    • latest

Version History

Package Sidebar

Install

npm i @mpen/rerouter

Weekly Downloads

1

Version

0.1.9

License

MIT

Unpacked Size

32.5 kB

Total Files

9

Last publish

Collaborators

  • mnpenner