aboutsummaryrefslogtreecommitdiff
path: root/frontend/ts/src/lib/router.ts
diff options
context:
space:
mode:
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 }
+ }
+}