@koa/router 15.6.0 → 15.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +23 -23
  2. package/dist/index.mjs +23 -23
  3. package/package.json +11 -11
package/dist/index.js CHANGED
@@ -519,12 +519,12 @@ var Layer = class {
519
519
  * @private
520
520
  */
521
521
  _insertParamMiddleware(middlewareStack, parameterMiddleware, parameterNamesList, currentParameterPosition) {
522
- let inserted = false;
522
+ let isInserted = false;
523
523
  for (let stackIndex = 0; stackIndex < middlewareStack.length; stackIndex++) {
524
524
  const existingMiddleware = middlewareStack[stackIndex];
525
525
  if (!existingMiddleware.param) {
526
526
  middlewareStack.splice(stackIndex, 0, parameterMiddleware);
527
- inserted = true;
527
+ isInserted = true;
528
528
  break;
529
529
  }
530
530
  const existingParameterPosition = parameterNamesList.indexOf(
@@ -532,11 +532,11 @@ var Layer = class {
532
532
  );
533
533
  if (existingParameterPosition > currentParameterPosition) {
534
534
  middlewareStack.splice(stackIndex, 0, parameterMiddleware);
535
- inserted = true;
535
+ isInserted = true;
536
536
  break;
537
537
  }
538
538
  }
539
- if (!inserted) {
539
+ if (!isInserted) {
540
540
  middlewareStack.push(parameterMiddleware);
541
541
  }
542
542
  }
@@ -565,9 +565,9 @@ var Layer = class {
565
565
  _applyPrefix(prefixPath) {
566
566
  const isRootPath = this.path === "/";
567
567
  const isStrictMode = this.opts.strict === true;
568
- const prefixHasParameters = prefixPath.includes(":");
569
- const pathIsRawRegex = this.opts.pathAsRegExp === true && typeof this.path === "string";
570
- if (prefixHasParameters && pathIsRawRegex) {
568
+ const isPrefixHasParameters = prefixPath.includes(":");
569
+ const isPathIsRawRegex = this.opts.pathAsRegExp === true && typeof this.path === "string";
570
+ if (isPrefixHasParameters && isPathIsRawRegex) {
571
571
  const currentPath = this.path;
572
572
  if (currentPath === String.raw`(?:\/|$)` || currentPath === String.raw`(?:\\\/|$)`) {
573
573
  this.path = "{/*rest}";
@@ -584,9 +584,9 @@ var Layer = class {
584
584
  * @private
585
585
  */
586
586
  _reconfigurePathMatching(prefixPath) {
587
- const treatAsRegExp = this.opts.pathAsRegExp === true;
587
+ const isTreatAsRegExp = this.opts.pathAsRegExp === true;
588
588
  const prefixHasParameters = prefixPath && prefixPath.includes(":");
589
- if (prefixHasParameters && treatAsRegExp) {
589
+ if (prefixHasParameters && isTreatAsRegExp) {
590
590
  const options = normalizeLayerOptionsToPathToRegexp(this.opts);
591
591
  const { regexp, keys } = compilePathToRegexp(
592
592
  this.path,
@@ -595,7 +595,7 @@ var Layer = class {
595
595
  this.regexp = regexp;
596
596
  this.paramNames = keys;
597
597
  this.opts.pathAsRegExp = false;
598
- } else if (treatAsRegExp) {
598
+ } else if (isTreatAsRegExp) {
599
599
  const pathString = this.path;
600
600
  const anchoredPattern = pathString.startsWith("^") ? pathString : `^${pathString}`;
601
601
  this.regexp = this.path instanceof RegExp ? this.path : new RegExp(anchoredPattern);
@@ -783,10 +783,10 @@ var RouterImplementation = class {
783
783
  return temporaryLayer.url(...arguments_);
784
784
  }
785
785
  use(...middleware) {
786
- let explicitPath;
787
786
  if (this._isPathArray(middleware[0])) {
788
787
  return this._useWithPathArray(middleware);
789
788
  }
789
+ let explicitPath;
790
790
  const hasExplicitPath = this._hasExplicitPath(middleware[0]);
791
791
  if (hasExplicitPath) {
792
792
  explicitPath = middleware.shift();
@@ -924,33 +924,33 @@ var RouterImplementation = class {
924
924
  * @private
925
925
  */
926
926
  _registerMiddleware(middleware, explicitPath, hasExplicitPath) {
927
- const prefixHasParameters = hasPathParameters(
927
+ const isPrefixHasParameters = hasPathParameters(
928
928
  this.opts.prefix || "",
929
929
  this.opts
930
930
  );
931
931
  const effectiveExplicitPath = (() => {
932
932
  if (explicitPath !== void 0) return explicitPath;
933
- if (prefixHasParameters) return "";
933
+ if (isPrefixHasParameters) return "";
934
934
  return;
935
935
  })();
936
- const effectiveHasExplicitPath = hasExplicitPath || explicitPath === void 0 && prefixHasParameters;
936
+ const isEffectiveHasExplicitPath = hasExplicitPath || explicitPath === void 0 && isPrefixHasParameters;
937
937
  const { path: middlewarePath, pathAsRegExp } = determineMiddlewarePath(
938
938
  effectiveExplicitPath,
939
- prefixHasParameters
939
+ isPrefixHasParameters
940
940
  );
941
941
  let finalPath = middlewarePath;
942
- let usePathToRegexp = pathAsRegExp;
943
- const isRootPath = effectiveHasExplicitPath && middlewarePath === "/";
944
- if (effectiveHasExplicitPath && typeof middlewarePath === "string") {
942
+ let isUsePathToRegexp = pathAsRegExp;
943
+ const isRootPath = isEffectiveHasExplicitPath && middlewarePath === "/";
944
+ if (isEffectiveHasExplicitPath && typeof middlewarePath === "string") {
945
945
  finalPath = middlewarePath;
946
- usePathToRegexp = false;
946
+ isUsePathToRegexp = false;
947
947
  }
948
948
  const ignoreWildcardParameter = effectiveExplicitPath === "" && middlewarePath === "{/*rest}" ? "rest" : void 0;
949
949
  this.register(finalPath, [], middleware, {
950
950
  end: isRootPath,
951
- ignoreCaptures: !effectiveHasExplicitPath && !prefixHasParameters,
951
+ ignoreCaptures: !isEffectiveHasExplicitPath && !isPrefixHasParameters,
952
952
  ignoreWildcardParameter,
953
- pathAsRegExp: usePathToRegexp
953
+ pathAsRegExp: isUsePathToRegexp
954
954
  });
955
955
  }
956
956
  /**
@@ -1473,8 +1473,8 @@ var RouterImplementation = class {
1473
1473
  if (layer.match(path)) {
1474
1474
  matchResult.path.push(layer);
1475
1475
  const isMiddleware = layer.methods.length === 0;
1476
- const matchesMethod = layer.methods.includes(normalizedMethod);
1477
- if (isMiddleware || matchesMethod) {
1476
+ const isMatchesMethod = layer.methods.includes(normalizedMethod);
1477
+ if (isMiddleware || isMatchesMethod) {
1478
1478
  matchResult.pathAndMethod.push(layer);
1479
1479
  if (layer.methods.length > 0) {
1480
1480
  matchResult.route = true;
package/dist/index.mjs CHANGED
@@ -480,12 +480,12 @@ var Layer = class {
480
480
  * @private
481
481
  */
482
482
  _insertParamMiddleware(middlewareStack, parameterMiddleware, parameterNamesList, currentParameterPosition) {
483
- let inserted = false;
483
+ let isInserted = false;
484
484
  for (let stackIndex = 0; stackIndex < middlewareStack.length; stackIndex++) {
485
485
  const existingMiddleware = middlewareStack[stackIndex];
486
486
  if (!existingMiddleware.param) {
487
487
  middlewareStack.splice(stackIndex, 0, parameterMiddleware);
488
- inserted = true;
488
+ isInserted = true;
489
489
  break;
490
490
  }
491
491
  const existingParameterPosition = parameterNamesList.indexOf(
@@ -493,11 +493,11 @@ var Layer = class {
493
493
  );
494
494
  if (existingParameterPosition > currentParameterPosition) {
495
495
  middlewareStack.splice(stackIndex, 0, parameterMiddleware);
496
- inserted = true;
496
+ isInserted = true;
497
497
  break;
498
498
  }
499
499
  }
500
- if (!inserted) {
500
+ if (!isInserted) {
501
501
  middlewareStack.push(parameterMiddleware);
502
502
  }
503
503
  }
@@ -526,9 +526,9 @@ var Layer = class {
526
526
  _applyPrefix(prefixPath) {
527
527
  const isRootPath = this.path === "/";
528
528
  const isStrictMode = this.opts.strict === true;
529
- const prefixHasParameters = prefixPath.includes(":");
530
- const pathIsRawRegex = this.opts.pathAsRegExp === true && typeof this.path === "string";
531
- if (prefixHasParameters && pathIsRawRegex) {
529
+ const isPrefixHasParameters = prefixPath.includes(":");
530
+ const isPathIsRawRegex = this.opts.pathAsRegExp === true && typeof this.path === "string";
531
+ if (isPrefixHasParameters && isPathIsRawRegex) {
532
532
  const currentPath = this.path;
533
533
  if (currentPath === String.raw`(?:\/|$)` || currentPath === String.raw`(?:\\\/|$)`) {
534
534
  this.path = "{/*rest}";
@@ -545,9 +545,9 @@ var Layer = class {
545
545
  * @private
546
546
  */
547
547
  _reconfigurePathMatching(prefixPath) {
548
- const treatAsRegExp = this.opts.pathAsRegExp === true;
548
+ const isTreatAsRegExp = this.opts.pathAsRegExp === true;
549
549
  const prefixHasParameters = prefixPath && prefixPath.includes(":");
550
- if (prefixHasParameters && treatAsRegExp) {
550
+ if (prefixHasParameters && isTreatAsRegExp) {
551
551
  const options = normalizeLayerOptionsToPathToRegexp(this.opts);
552
552
  const { regexp, keys } = compilePathToRegexp(
553
553
  this.path,
@@ -556,7 +556,7 @@ var Layer = class {
556
556
  this.regexp = regexp;
557
557
  this.paramNames = keys;
558
558
  this.opts.pathAsRegExp = false;
559
- } else if (treatAsRegExp) {
559
+ } else if (isTreatAsRegExp) {
560
560
  const pathString = this.path;
561
561
  const anchoredPattern = pathString.startsWith("^") ? pathString : `^${pathString}`;
562
562
  this.regexp = this.path instanceof RegExp ? this.path : new RegExp(anchoredPattern);
@@ -744,10 +744,10 @@ var RouterImplementation = class {
744
744
  return temporaryLayer.url(...arguments_);
745
745
  }
746
746
  use(...middleware) {
747
- let explicitPath;
748
747
  if (this._isPathArray(middleware[0])) {
749
748
  return this._useWithPathArray(middleware);
750
749
  }
750
+ let explicitPath;
751
751
  const hasExplicitPath = this._hasExplicitPath(middleware[0]);
752
752
  if (hasExplicitPath) {
753
753
  explicitPath = middleware.shift();
@@ -885,33 +885,33 @@ var RouterImplementation = class {
885
885
  * @private
886
886
  */
887
887
  _registerMiddleware(middleware, explicitPath, hasExplicitPath) {
888
- const prefixHasParameters = hasPathParameters(
888
+ const isPrefixHasParameters = hasPathParameters(
889
889
  this.opts.prefix || "",
890
890
  this.opts
891
891
  );
892
892
  const effectiveExplicitPath = (() => {
893
893
  if (explicitPath !== void 0) return explicitPath;
894
- if (prefixHasParameters) return "";
894
+ if (isPrefixHasParameters) return "";
895
895
  return;
896
896
  })();
897
- const effectiveHasExplicitPath = hasExplicitPath || explicitPath === void 0 && prefixHasParameters;
897
+ const isEffectiveHasExplicitPath = hasExplicitPath || explicitPath === void 0 && isPrefixHasParameters;
898
898
  const { path: middlewarePath, pathAsRegExp } = determineMiddlewarePath(
899
899
  effectiveExplicitPath,
900
- prefixHasParameters
900
+ isPrefixHasParameters
901
901
  );
902
902
  let finalPath = middlewarePath;
903
- let usePathToRegexp = pathAsRegExp;
904
- const isRootPath = effectiveHasExplicitPath && middlewarePath === "/";
905
- if (effectiveHasExplicitPath && typeof middlewarePath === "string") {
903
+ let isUsePathToRegexp = pathAsRegExp;
904
+ const isRootPath = isEffectiveHasExplicitPath && middlewarePath === "/";
905
+ if (isEffectiveHasExplicitPath && typeof middlewarePath === "string") {
906
906
  finalPath = middlewarePath;
907
- usePathToRegexp = false;
907
+ isUsePathToRegexp = false;
908
908
  }
909
909
  const ignoreWildcardParameter = effectiveExplicitPath === "" && middlewarePath === "{/*rest}" ? "rest" : void 0;
910
910
  this.register(finalPath, [], middleware, {
911
911
  end: isRootPath,
912
- ignoreCaptures: !effectiveHasExplicitPath && !prefixHasParameters,
912
+ ignoreCaptures: !isEffectiveHasExplicitPath && !isPrefixHasParameters,
913
913
  ignoreWildcardParameter,
914
- pathAsRegExp: usePathToRegexp
914
+ pathAsRegExp: isUsePathToRegexp
915
915
  });
916
916
  }
917
917
  /**
@@ -1434,8 +1434,8 @@ var RouterImplementation = class {
1434
1434
  if (layer.match(path)) {
1435
1435
  matchResult.path.push(layer);
1436
1436
  const isMiddleware = layer.methods.length === 0;
1437
- const matchesMethod = layer.methods.includes(normalizedMethod);
1438
- if (isMiddleware || matchesMethod) {
1437
+ const isMatchesMethod = layer.methods.includes(normalizedMethod);
1438
+ if (isMiddleware || isMatchesMethod) {
1439
1439
  matchResult.pathAndMethod.push(layer);
1440
1440
  if (layer.methods.length > 0) {
1441
1441
  matchResult.route = true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koa/router",
3
3
  "description": "Router middleware for Koa.",
4
- "version": "15.6.0",
4
+ "version": "15.7.0",
5
5
  "author": "Koa.js",
6
6
  "bugs": {
7
7
  "url": "https://github.com/koajs/router/issues",
@@ -31,28 +31,28 @@
31
31
  "path-to-regexp": "^8.4.2"
32
32
  },
33
33
  "devDependencies": {
34
- "@commitlint/cli": "^21.0.2",
35
- "@commitlint/config-conventional": "^21.0.2",
34
+ "@commitlint/cli": "^21.2.0",
35
+ "@commitlint/config-conventional": "^21.2.0",
36
36
  "@eslint/js": "^10.0.1",
37
37
  "@koa/bodyparser": "^6.1.0",
38
38
  "@types/debug": "^4.1.13",
39
39
  "@types/jsonwebtoken": "^9.0.10",
40
40
  "@types/koa": "^3.0.3",
41
- "@types/node": "^25.9.1",
41
+ "@types/node": "^26.1.0",
42
42
  "@types/supertest": "^7.2.0",
43
- "@typescript-eslint/eslint-plugin": "^8.60.0",
44
- "@typescript-eslint/parser": "^8.60.0",
43
+ "@typescript-eslint/eslint-plugin": "^8.62.1",
44
+ "@typescript-eslint/parser": "^8.62.1",
45
45
  "c8": "^11.0.0",
46
46
  "chalk": "^5.6.2",
47
- "eslint": "^10.4.1",
48
- "eslint-plugin-unicorn": "^64.0.0",
47
+ "eslint": "^10.6.0",
48
+ "eslint-plugin-unicorn": "^70.0.0",
49
49
  "husky": "^9.1.7",
50
- "joi": "^18.2.1",
50
+ "joi": "^18.2.3",
51
51
  "jsonwebtoken": "^9.0.3",
52
52
  "koa": "^3.2.1",
53
- "lint-staged": "^17.0.6",
53
+ "lint-staged": "^17.0.8",
54
54
  "np": "^11.2.1",
55
- "prettier": "^3.8.3",
55
+ "prettier": "^3.9.4",
56
56
  "rimraf": "^6.1.3",
57
57
  "supertest": "^7.2.2",
58
58
  "ts-node": "^10.9.2",