@mpen/rerouter 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +23 -11
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2023 Mark Penner
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
Created with [`ctslib`](https://yarnpkg.com/en/package/create-tslib).
|
|
4
|
-
|
|
5
|
-
## Getting Started
|
|
1
|
+
# @mpen/rerouter
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
An implementation of [RFC 6570: URI Template](https://tools.ietf.org/html/rfc6570).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
8
6
|
|
|
9
7
|
```sh
|
|
10
|
-
|
|
8
|
+
bun add @mpen/rerouter
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
## API
|
|
14
12
|
|
|
15
|
-
```
|
|
16
|
-
|
|
13
|
+
```ts
|
|
14
|
+
const templ = new UriTemplate('/query{?firstName,lastName}')
|
|
15
|
+
console.log(templ.match('/query?firstName=Bj%c3%b6rk&lastName=Gu%c3%b0mundsd%c3%b3ttir'))
|
|
16
|
+
// {
|
|
17
|
+
// score: 7,
|
|
18
|
+
// params: {
|
|
19
|
+
// firstName: "Björk",
|
|
20
|
+
// lastName: "Guðmundsdóttir"
|
|
21
|
+
// }
|
|
22
|
+
// }
|
|
23
|
+
console.log(templ.expand({firstName: 'Mark', lastName: 'Penner'}))
|
|
24
|
+
// /query?firstName=Mark&lastName=Penner
|
|
17
25
|
```
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
That's it. That's the whole API. 2 methods.
|
|
28
|
+
|
|
29
|
+
It's been tested against https://github.com/uri-templates/uritemplate-test and all 157 tests pass.
|
|
30
|
+
|
|
31
|
+
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.
|