@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.
Files changed (3) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +23 -11
  3. package/package.json +1 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 Mark Penner
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
- # YourLib
2
-
3
- Created with [`ctslib`](https://yarnpkg.com/en/package/create-tslib).
4
-
5
- ## Getting Started
1
+ # @mpen/rerouter
6
2
 
7
- ### Run source code directly
3
+ An implementation of [RFC 6570: URI Template](https://tools.ietf.org/html/rfc6570).
4
+
5
+ ## Installation
8
6
 
9
7
  ```sh
10
- make dev
8
+ bun add @mpen/rerouter
11
9
  ```
12
10
 
13
- ### Build code for production
11
+ ## API
14
12
 
15
- ```sh
16
- make
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
- It will be written to `dist/`. After that, you don't need TypeScript nor babel installed. It can be distributed for node LTS.
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpen/rerouter",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "packageManager": "bun",
5
5
  "exports": "./dist/bundle.cjs",
6
6
  "module": "./dist/bundle.mjs",