summaryrefslogtreecommitdiff
path: root/node_modules/express/lib/router/collection.js
blob: 991a9a239c32bb29fb1fe8afac370835fa125ca6 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*!
 * Express - router - Collection
 * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
 * MIT Licensed
 */

/**
 * Expose `Collection`.
 */

module.exports = Collection;

/**
 * Initialize a new route `Collection`
 * with the given `router`.
 * 
 * @param {Router} router
 * @api private
 */

function Collection(router) {
  Array.apply(this, arguments);
  this.router = router;
}

/**
 * Inherit from `Array.prototype`.
 */

Collection.prototype.__proto__ = Array.prototype;

/**
 * Remove the routes in this collection.
 *
 * @return {Collection} of routes removed
 * @api public
 */

Collection.prototype.remove = function(){
  var router = this.router
    , len = this.length
    , ret = new Collection(this.router);

  for (var i = 0; i < len; ++i) {
    if (router.remove(this[i])) {
      ret.push(this[i]);
    }
  }

  return ret;
};