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

@koa/router

Package Overview
Dependencies
Maintainers
0
Versions
26
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 13.0.1 to 13.1.0

HISTORY.md

37

lib/layer.js
const { parse: parseUrl, format: formatUrl } = require('node:url');
const { pathToRegexp, compile, parse, stringify } = require('path-to-regexp');
const { pathToRegexp, compile, parse } = require('path-to-regexp');

@@ -16,3 +16,2 @@ module.exports = class Layer {

* @param {String=} opts.strict require the trailing slash (default: false)
* @param {Boolean=} opts.pathIsRegexp if true, treat `path` as a regular expression
* @returns {Layer}

@@ -46,15 +45,3 @@ * @private

this.path = path;
if (this.opts.pathIsRegexp === true) {
this.regexp = new RegExp(path);
} else if (this.path) {
if (this.opts.strict === true) {
// path-to-regexp renamed strict to trailing in v8.1.0
this.opts.trailing = false;
}
const { regexp: regex, keys } = pathToRegexp(this.path, this.opts);
this.regexp = regex;
this.paramNames = keys;
}
this.regexp = pathToRegexp(path, this.paramNames, this.opts);
}

@@ -134,3 +121,4 @@

let replaced;
const { tokens } = parse(url);
const tokens = parse(url);
let replace = {};

@@ -140,5 +128,3 @@

for (let len = tokens.length, i = 0, j = 0; i < len; i++) {
if (tokens[i].name) {
replace[tokens[i].name] = args[j++];
}
if (tokens[i].name) replace[tokens[i].name] = args[j++];
}

@@ -151,6 +137,2 @@ } else if (tokens.some((token) => token.name)) {

for (const [key, value] of Object.entries(replace)) {
replace[key] = String(value);
}
replaced = toPath(replace);

@@ -238,9 +220,4 @@

: prefix;
if (this.opts.pathIsRegexp === true || prefix instanceof RegExp) {
this.regexp = new RegExp(this.path);
} else if (this.path) {
const { regexp: regex, keys } = pathToRegexp(this.path, this.opts);
this.regexp = regex;
this.paramNames = keys;
}
this.paramNames = [];
this.regexp = pathToRegexp(this.path, this.paramNames, this.opts);
}

@@ -247,0 +224,0 @@

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

} else {
const { keys } = pathToRegexp(router.opts.prefix || '', router.opts);
const keys = [];
pathToRegexp(router.opts.prefix || '', keys);
const routerPrefixHasParam = Boolean(

@@ -175,4 +176,3 @@ router.opts.prefix && keys.length > 0

end: false,
ignoreCaptures: !hasPath && !routerPrefixHasParam,
pathIsRegexp: true
ignoreCaptures: !hasPath && !routerPrefixHasParam
});

@@ -385,3 +385,3 @@ }

all(name, path, middleware) {
if (typeof path === 'string' || path instanceof RegExp) {
if (typeof path === 'string') {
middleware = Array.prototype.slice.call(arguments, 2);

@@ -402,9 +402,4 @@ } else {

const opts = {
name,
pathIsRegexp: path instanceof RegExp
};
this.register(path, methods, middleware, { name });
this.register(path, methods, middleware, { ...this.opts, ...opts });
return this;

@@ -467,6 +462,6 @@ }

*/
register(path, methods, middleware, newOpts = {}) {
register(path, methods, middleware, opts = {}) {
const router = this;
const { stack } = this;
const opts = { ...this.opts, ...newOpts };
// support array of paths

@@ -485,10 +480,8 @@ if (Array.isArray(path)) {

name: opts.name,
sensitive: opts.sensitive || false,
strict: opts.strict || false,
prefix: opts.prefix || '',
ignoreCaptures: opts.ignoreCaptures,
pathIsRegexp: opts.pathIsRegexp
sensitive: opts.sensitive || this.opts.sensitive || false,
strict: opts.strict || this.opts.strict || false,
prefix: opts.prefix || this.opts.prefix || '',
ignoreCaptures: opts.ignoreCaptures
});
// if parent prefix exists, add prefix to new route
if (this.opts.prefix) {

@@ -828,9 +821,4 @@ route.setPrefix(this.opts.prefix);

const opts = {
name,
pathIsRegexp: path instanceof RegExp
};
this.register(path, [method], middleware, { name });
// pass opts to register call on verb methods
this.register(path, [method], middleware, { ...this.opts, ...opts });
return this;

@@ -837,0 +825,0 @@ };

{
"name": "@koa/router",
"description": "Router middleware for koa. Maintained by Forward Email and Lad.",
"version": "13.0.1",
"version": "13.1.0",
"author": "Alex Mingoia <talk@alexmingoia.com>",

@@ -26,3 +26,3 @@ "bugs": {

"koa-compose": "^4.1.0",
"path-to-regexp": "^8.1.0"
"path-to-regexp": "^6.3.0"
},

@@ -72,3 +72,3 @@ "devDependencies": {

"prepare": "husky install",
"pretest": "npm run lint",
"prextest": "npm run lint",
"test": "mocha test/**/*.js",

@@ -75,0 +75,0 @@ "test:watch": "mocha test/**/*.js --watch"

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