@vercel/routing-utils 3.0.0 → 3.1.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.
package/dist/append.js CHANGED
@@ -1,45 +1,66 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.appendRoutesToPhase = void 0;
4
- const index_1 = require("./index");
5
- function appendRoutesToPhase({ routes: prevRoutes, newRoutes, phase, }) {
6
- const routes = prevRoutes ? [...prevRoutes] : [];
7
- if (newRoutes === null || newRoutes.length === 0) {
8
- return routes;
9
- }
10
- let isInPhase = false;
11
- let insertIndex = -1;
12
- routes.forEach((r, i) => {
13
- if ((0, index_1.isHandler)(r)) {
14
- if (r.handle === phase) {
15
- isInPhase = true;
16
- }
17
- else if (isInPhase) {
18
- insertIndex = i;
19
- isInPhase = false;
20
- }
21
- }
22
- });
23
- if (isInPhase) {
24
- routes.push(...newRoutes);
25
- }
26
- else if (phase === null) {
27
- // If the phase is null, we want to insert the routes at the beginning
28
- const lastPhase = routes.findIndex(r => (0, index_1.isHandler)(r) && r.handle);
29
- if (lastPhase === -1) {
30
- routes.push(...newRoutes);
31
- }
32
- else {
33
- routes.splice(lastPhase, 0, ...newRoutes);
34
- }
35
- }
36
- else if (insertIndex > -1) {
37
- routes.splice(insertIndex, 0, ...newRoutes);
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var append_exports = {};
20
+ __export(append_exports, {
21
+ appendRoutesToPhase: () => appendRoutesToPhase
22
+ });
23
+ module.exports = __toCommonJS(append_exports);
24
+ var import_index = require("./index");
25
+ function appendRoutesToPhase({
26
+ routes: prevRoutes,
27
+ newRoutes,
28
+ phase
29
+ }) {
30
+ const routes = prevRoutes ? [...prevRoutes] : [];
31
+ if (newRoutes === null || newRoutes.length === 0) {
32
+ return routes;
33
+ }
34
+ let isInPhase = false;
35
+ let insertIndex = -1;
36
+ routes.forEach((r, i) => {
37
+ if ((0, import_index.isHandler)(r)) {
38
+ if (r.handle === phase) {
39
+ isInPhase = true;
40
+ } else if (isInPhase) {
41
+ insertIndex = i;
42
+ isInPhase = false;
43
+ }
38
44
  }
39
- else {
40
- routes.push({ handle: phase });
41
- routes.push(...newRoutes);
45
+ });
46
+ if (isInPhase) {
47
+ routes.push(...newRoutes);
48
+ } else if (phase === null) {
49
+ const lastPhase = routes.findIndex((r) => (0, import_index.isHandler)(r) && r.handle);
50
+ if (lastPhase === -1) {
51
+ routes.push(...newRoutes);
52
+ } else {
53
+ routes.splice(lastPhase, 0, ...newRoutes);
42
54
  }
43
- return routes;
55
+ } else if (insertIndex > -1) {
56
+ routes.splice(insertIndex, 0, ...newRoutes);
57
+ } else {
58
+ routes.push({ handle: phase });
59
+ routes.push(...newRoutes);
60
+ }
61
+ return routes;
44
62
  }
45
- exports.appendRoutesToPhase = appendRoutesToPhase;
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ appendRoutesToPhase
66
+ });