You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.1 KiB
30 lines
1.1 KiB
import {Route, RouteParameters, RouteSegment} from './Route.ts'
|
|
import Utility from '../../service/utility/Utility.ts'
|
|
import {make} from '../../../../di/src/global.ts'
|
|
|
|
export class ComplexRoute extends Route {
|
|
public match(incoming: string): boolean {
|
|
const base_length = this.split(this.base).length
|
|
const incoming_length = this.split(incoming).length
|
|
return base_length === incoming_length // FIXME match!
|
|
}
|
|
|
|
public build_parameters(incoming: string): RouteParameters {
|
|
const utility = make(Utility)
|
|
const params: RouteParameters = {}
|
|
let current_wildcard: number = 1
|
|
|
|
this.zip(incoming).forEach((segment: RouteSegment) => {
|
|
if ( segment.base.indexOf('*') >= 0 ) {
|
|
params[`$${current_wildcard}`] = utility.infer(segment.match)
|
|
current_wildcard += 1
|
|
} else if ( segment.base.startsWith(':') && segment.base.length > 1 ) {
|
|
const name = segment.base.substr(1)
|
|
params[name] = utility.infer(segment.match)
|
|
}
|
|
})
|
|
|
|
return params
|
|
}
|
|
}
|