Socket
Socket
Sign inDemoInstall

koa-router

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-router - npm Package Compare versions

Comparing version 3.2.1 to 3.2.2

11

lib/route.js

@@ -45,2 +45,13 @@ /**

// ensure middleware is a function
middleware.forEach(function(fn) {
var type = (typeof fn);
if (type != 'function') {
throw new Error(
methods.toString() + " `" + (name || path) +"`: `middleware` "
+ "must be a function, not `" + type + "`"
);
}
});
if (middleware.length > 1) {

@@ -47,0 +58,0 @@ this.middleware = compose(middleware);

3

lib/router.js

@@ -122,4 +122,3 @@ /**

var args = Array.prototype.slice.call(arguments);
args.splice(typeof path == 'function' ? 1 : 2, 0, [method]);
args.splice(typeof path == 'string' ? 2 : 1, 0, [method]);
this.register.apply(this, args);

@@ -126,0 +125,0 @@ return this;

@@ -9,3 +9,3 @@ {

"author": "Alex Mingoia <talk@alexmingoia.com>",
"version": "3.2.1",
"version": "3.2.2",
"keywords": [

@@ -12,0 +12,0 @@ "koa",

@@ -154,3 +154,20 @@ /**

});
})
});
it('should throw friendly error message when handle not exists', function() {
var app = koa();
app.use(router(app));
var notexistHandle = undefined;
(function () {
app.get('/foo', notexistHandle);
}).should.throw('get `/foo`: `middleware` must be a function, not `undefined`');
(function () {
app.get('foo router', '/foo', notexistHandle);
}).should.throw('get `foo router`: `middleware` must be a function, not `undefined`');
(function () {
app.post('/foo', function() {}, notexistHandle);
}).should.throw('post `/foo`: `middleware` must be a function, not `undefined`');
});
});

@@ -160,3 +177,3 @@

it('generates route URL', function() {
var route = new Route('/:category/:title', ['get'], function* () {}, 'books');
var route = new Route('/:category/:title', ['get'], [function* () {}], 'books');
var url = route.url({ category: 'programming', title: 'how-to-node' });

@@ -169,3 +186,3 @@ url.should.equal('/programming/how-to-node');

it('escapes using encodeURIComponent()', function() {
var route = new Route('/:category/:title', ['get'], function *() {}, 'books');
var route = new Route('/:category/:title', ['get'], [function *() {}], 'books');
var url = route.url({ category: 'programming', title: 'how to node' });

@@ -172,0 +189,0 @@ url.should.equal('/programming/how%20to%20node');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc