UNPKG

1.24 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3function provideRoutes(app, exlcudePath) {
4 const routes = [];
5 function normalizeInfo(path, methods) {
6 if (path !== exlcudePath) {
7 routes.push({
8 method: Object.keys(methods)
9 .filter((key) => methods[key])
10 .join(","),
11 path,
12 });
13 }
14 }
15 // eslint-disable-next-line no-underscore-dangle
16 app._router.stack.forEach((r) => {
17 if (r.route && r.route.path) {
18 const { path } = r.route;
19 const { methods } = r.route;
20 if (Array.isArray(path)) {
21 path.forEach((v) => normalizeInfo(v, methods));
22 }
23 else {
24 normalizeInfo(path, methods);
25 }
26 }
27 });
28 function stringCompare(v1, v2) {
29 return v1.localeCompare(v2, undefined, {
30 sensitivity: "base",
31 ignorePunctuation: true,
32 numeric: true,
33 });
34 }
35 return routes.sort((v1, v2) => stringCompare(v1.method, v2.method) || stringCompare(v1.path, v2.path));
36}
37exports.default = provideRoutes;