Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lark-router

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lark-router - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

lib/Route.js

16

lib/Router.js

@@ -8,5 +8,5 @@ /**

const events = require('events');
const path2regexp = require('path-to-regexp');
const methods = require('./methods');
const Route = require('./Route');
const Switcher = require('./Switcher');

@@ -21,3 +21,3 @@

route(method, route, handler) {
route(method, routePath, handler) {
const typeofMethod = typeof method;

@@ -29,15 +29,15 @@ assert('string' === typeofMethod, `Method should be a string, ${typeofMethod} given`);

assert('string' === typeof route || route instanceof RegExp,
`Route should be a string or a regular expression, ${typeof route} given`);
assert('string' === typeof routePath || routePath instanceof RegExp,
`Route should be a string or a regular expression, ${typeof routePath} given`);
let regexp = null;
let route = null;
if (handler instanceof Router) {
regexp = path2regexp(route, null, { end: false });
route = new Route(routePath, { end: false });
handler = handler.switcher;
}
else {
regexp = path2regexp(route);
route = new Route(routePath);
}
this.switcher.case({ method, regexp }, handler);
this.switcher.case({ method, route }, handler);
}

@@ -44,0 +44,0 @@

@@ -23,9 +23,9 @@ /**

const match = condition.regexp.exec(context.request.path);
if (!match) {
if ((condition.method === 'ROUTED' && !context.routed) ||
(condition.method === 'OTHER' && context.routed)) {
return false;
}
if ((condition.method === 'ROUTED' && !context.routed) ||
(condition.method === 'OTHER' && context.routed)) {
const match = condition.route.exec(context.request.path);
if (!match) {
return false;

@@ -36,4 +36,4 @@ }

context.params = context.superParams || {};
context.condition = condition;
const keys = condition.regexp.keys;
context.matched = match[0];
const keys = condition.route.keys;
let length = Object.keys(context.params).length;

@@ -57,3 +57,3 @@ let i = 1;

context.request = extend({}, context.request, true);
context.request.path = context.request.path.replace(context.condition.regexp, '');
context.request.path = context.request.path.slice(context.matched.length);
return context;

@@ -60,0 +60,0 @@ }

{
"name": "lark-router",
"version": "2.0.0",
"version": "2.1.0",
"description": "An koa route initialization and configuration module.",

@@ -31,3 +31,4 @@ "main": "./lib/Router.js",

"path-to-regexp": "^1.5.3",
"switch-case": "^0.4.0"
"switch-case": "^0.4.0",
"vi-misc": "^1.4.0"
},

@@ -34,0 +35,0 @@ "devDependencies": {

@@ -83,3 +83,3 @@ /**

describe('route with an http server', () => {
it('should response 200 for get /hello/haohao', (done) => {
it('should response 200 for get /hello//haohao', (done) => {
http.get('/hello/haohao')

@@ -86,0 +86,0 @@ .expect(200)

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