Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getRouteMap(annotations) {
/* jshint validthis:true */
if (!Array.isArray(annotations)) {
annotations = [].slice.call(arguments);
}
// Gather all mapped/named routePaths that have the specified `annotations`.
var appAnnotations = this.annotations,
routes = this.findAll(annotations.concat('name'));
// Creates a mapping of name -> route object. The route objects are shallow
// copies of a route's primary metadata.
return methods.reduce(function (map, method) {
var methodRoutes = routes[method];
if (!methodRoutes) { return map; }
methodRoutes.forEach(function (route) {
var pathAnnotations = appAnnotations[route.path],
name = pathAnnotations.name,
entry;
// Return early if the route has no canonical `name`, or if that
// name has already been mapped, in which case none of its `names`
// will be mapped.
if (!name || map[name]) { return; }
// The entry that represents the route in the route map.
entry = {