blob: 354976306caf1c66fe35b6cd294f90ea9d3cbdea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 }
}
}
|