aboutsummaryrefslogtreecommitdiff
path: root/frontend/ts/src/lib/router.ts
diff options
context:
space:
mode:
authorJoris2025-04-19 12:36:38 +0200
committerJoris2025-04-19 12:38:24 +0200
commit632eef6424d8dc8d40c2906177892697679e7b85 (patch)
tree48d9cd60e9e96eab810b5f7bb3c7b1fa79e0438f /frontend/ts/src/lib/router.ts
parent063d8ef9eaf874a941f4459e831057dd0a1b7ddd (diff)
Add ZIG server
Diffstat (limited to 'frontend/ts/src/lib/router.ts')
-rw-r--r--frontend/ts/src/lib/router.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/frontend/ts/src/lib/router.ts b/frontend/ts/src/lib/router.ts
new file mode 100644
index 0000000..3549763
--- /dev/null
+++ b/frontend/ts/src/lib/router.ts
@@ -0,0 +1,25 @@
+export interface Result {
+ data: { [key: string]: string }
+}
+
+export function matches(str: string, m: string): Result | undefined {
+ const strParts = str.split('/').slice(1)
+ const mParts = m.split('/').slice(1)
+
+ if (strParts.length == mParts.length) {
+ const data: { [key: string]: string } = {}
+
+ for (let i = 0; i < strParts.length; ++i) {
+ if (mParts[i].length > 0 && mParts[i][0] == ':') {
+ const key = mParts[i].substring(1)
+ data[key] = strParts[i]
+ } else {
+ if (strParts[i] !== mParts[i]) {
+ return undefined
+ }
+ }
+ }
+
+ return { data }
+ }
+}