Skip to content
Myr

added .index to match() retvals

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 c4e2ce2 · Browse files · 2 files+13 added−3 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+13 added−3 removed

  • tests:+9 added−0 removed
  • other:+4 added−3 removed

2 files+13 added−3 removed

modified:lib/router/index.js+4 added-3 removed
193 unmodified lines
194195 router.match = function(url, method, ret){196 var ret = ret || []197 , i = 0198 , fn198 , route199 , req;200201 // method specific matches202 if (method) {203 method = method.toUpperCase();204 req = { url: url, method: method };205 while (fn = match(req, routes, i)) {205 while (route = match(req, routes, i)) {206 i = req._route_index + 1;207 route.index = i;207 ret.push(fn);208 ret.push(route);209 } 210 // global matches211 } else {212 _methods.forEach(function(method){
89 unmodified lines
modified:test/express.test.js+9 added
619 unmodified lines
620 app.get('/user/:id/:op?', function(){});621 app.put('/user/:id', function(){});622 app.get('/user/:id/edit', function(){});623624 var route = app.match.get('/user/12')[0];625 route.should.be.an.instanceof(Route);626 route.callback.should.be.a('function');627 route.path.should.equal('/user/:id');628 route.regexp.should.be.an.instanceof(RegExp);629 route.method.should.equal('GET');630 route.index.should.equal(2);631 route.keys.should.eql(['id']);632633 app.match.get('/user').should.have.length(1);634 app.match.get('/user/12').should.have.length(2);635 app.match.get('/user/12/:op?').should.have.length(1);636 app.match.put('/user/100').should.have.length(1);
5 unmodified lines