Skip to content
Myr

Removed `Collection`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 9abba7d · Browse files · 2 files+0 added−158 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+0 added−158 removed

  • other:+0 added−158 removed

2 files+0 added−158 removed

deleted:lib/router/collection.js-52 removed
modified:lib/router/index.js-106 removed
7 unmodified lines
8 * Module dependencies.9 */1011var Route = require('./route')12 , Collection = require('./collection')12 , utils = require('../utils')13 , debug = require('debug')('express:router')14 , parse = require('url').parse;15
18 unmodified lines
3435function Router(options) {36 options = options || {};37 var self = this;39 this.routes = new Collection;38 this.map = {};39 this.params = {};40 this._params = [];41 this.caseSensitive = options.caseSensitive;
41 unmodified lines
83 return this;84};8586/**89 * Return a `Collection` of all routes defined.90 *91 * @return {Collection}92 * @api public93 */9495Router.prototype.all = function(){96 return this.find(function(){97 return true;98 });99};100101/**102 * Remove the given `route`, returns103 * a bool indicating if the route was present104 * or not.105 *106 * @param {Route} route107 * @return {Boolean}108 * @api public109 */110111Router.prototype.remove = function(route){112 var routes = this.map[route.method]113 , len = routes.length;114115 // remove from array116 var i = this.routes.indexOf(route);117 this.routes.splice(i, 1);118119 // remove from map120 for (var i = 0; i < len; ++i) {121 if (route == routes[i]) {122 routes.splice(i, 1);123 return true;124 }125 }126};127128/**129 * Return routes with route paths matching `path`.130 *131 * @param {String} method132 * @param {String} path133 * @return {Collection}134 * @api public135 */136137Router.prototype.lookup = function(method, path){138 return this.find(function(route){139 return path == route.path140 && (route.method == method141 || method == 'all');142 });143};144145// /**146// * Return routes with regexps that match the given `url`.147// *148// * @param {String} method149// * @param {String} url150// * @return {Collection}151// * @api public152// */153// 154// Router.prototype.match = function(method, url){155// return this.find(function(route){156// return route.match(url)157// && (route.method == method158// || method == 'all');159// });160// };161162/**163 * Find routes based on the return value of `fn`164 * which is invoked once per route.165 *166 * @param {Function} fn167 * @return {Collection}168 * @api public169 */170171Router.prototype.find = function(fn){172 var len = methods.length173 , ret = new Collection(this)174 , method175 , routes176 , route;177178 for (var i = 0; i < len; ++i) {179 method = methods[i];180 routes = this.map[method];181 if (!routes) continue;182 for (var j = 0, jlen = routes.length; j < jlen; ++j) {183 route = routes[j];184 if (fn(route)) ret.push(route);185 }186 }187188 return ret;189};190191/**87 * Route dispatcher aka the route "middleware".88 *89 * @param {IncomingMessage} req90 * @param {ServerResponse} res
218 unmodified lines
309 });310311 // add it312 (this.map[method] = this.map[method] || []).push(route);418 this.routes.push(route);313 return this;314};