API

Router

Computes a routing table for several Routes and evaluates matches for input URIs.

clear()
Reset the Router to have zero entries.
addTemplate(pattern, options, matchValue)
Adds a route to the router. Returns the Route object that was inserted. pattern may be a Route object or a URI Template string. Options is passed to the new Route object, if created. The route cannot partially overlap any other route (there cannot be two routes A and B so that one URI matches only A, and URI matches only B, and some third URI matches both A and B.)
hasRoute(route)
Test if the router has the specified Route.
size
The number of routes in the Router.
getTemplate(uriTemplate)
Get the Route in the Router that has the given uriTemplate.
hasTemplate(uriTemplate)
Test if the router has a Route with the given uriTemplate.
getValue(matchValue)
Get the Route in the Router that has the given matchValue. This only maps the initial first value of Route#matchValue, it will not update if is changed directly, or if a duplicate value is inserted.
hasValue(matchValue)
Test if the router has a Route with the given matchValue.
resolveURI(uri)
Determine if the routing table has a match for uri. Returns a Result object with the best match.

Route

A Route identifies a single URI Template. It can be inserted into a Router, or can be supplied data to expand into a full URI.

new Route(uriTemplate, options)
Options may have the following properties:
parent
Route. Take the intersection of the provided route, which forces this route to be a subset of it.
matchValue
any. An arbitrary value to associate with this Route, available to the application when this route is selected as a match, or undefined if no match.
uriTemplate
The operator character opening the expression, such as + or ?, or an empty string if none.
matchValue
The operator character opening the expression, such as + or ?, or an empty string if none.
toString(params)
Returns a string of the URI Template, expanded with the given params.
resolveURI(uri)
Determine if this route is a match for uri. Returns a Result object with the match results, or undefined if no match.

Expression

Represents each curly-braced segment in a URI Template. Instances carry the following properties:

operatorChar
The operator character opening the expression, such as + or ?, or an empty string if none.
prefix
The leading character that will be output if one of the variables is defined.
separator
The character that will separate defined variables in the expression, if there are multiple.
range
The set of ASCII characters that will pass through without escaping.
variableList
An Array of Variable instances.

Variable

A variable inside an expression. Instances carry the following properties:

operatorChar
The operator character opening the expression the variable is in, such as + or ?, or an empty string if none.
varname
The name of the variable. Does not include the operator or modifiers.
explode
Boolean indicating the presence of an explode modifier.
maxLength
A number indicating the value of the "prefix" modifier, if one is supplied.
optional
A boolean indicating if this variable can be skipped when parsing a URI.
prefix
The leading character that begins the expression, if one of the variables is defined.
separator
The character that will separate this variable, if defined, from other defined variables.
delimiter
Like the separator, but only for characters used to delimit new values during reading.
range
The set of ASCII characters that will pass through without escaping.
named
Boolean indicating if the variable name will be printed before the value.

Result

router
The Router associated with this result.
uri
The URI that the resolve was called with.
options
(No function at present.)
route
The Route that was matched.
uriTemplate
The URI Template that was matched, shortcut for Result#route.template
matchValue
The matchValue property stored with the Route.
params
An object of the matched parameters/variables.