@modern-js/utils 2.22.1-alpha.1 → 2.22.1-alpha.3

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.
@@ -20,6 +20,8 @@ _export(exports, {
20
20
  return _serialize.serializeJson;
21
21
  }
22
22
  });
23
+ const _export_star = require("@swc/helpers/_/_export_star");
23
24
  const _storage = require("./storage");
24
25
  const _serialize = require("./serialize");
26
+ _export_star._(require("./nestedRoutes"), exports);
25
27
  const { run, useContext: useHeaders } = (0, _storage.createStorage)();
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "matchEntry", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return matchEntry;
9
+ }
10
+ });
11
+ function sortByUrlPath(entries) {
12
+ entries.sort(function(a, b) {
13
+ const length1 = a.urlPath.length;
14
+ const length2 = b.urlPath.length;
15
+ if (length1 < length2) {
16
+ return 1;
17
+ }
18
+ if (length1 > length2) {
19
+ return -1;
20
+ }
21
+ return 0;
22
+ });
23
+ return entries;
24
+ }
25
+ const matchEntry = (pathname, entries) => {
26
+ sortByUrlPath(entries);
27
+ return entries.find((entry) => pathname.startsWith(entry.urlPath));
28
+ };
@@ -2,3 +2,4 @@ import { createStorage } from "./storage";
2
2
  const { run, useContext: useHeaders } = createStorage();
3
3
  export { run, useHeaders };
4
4
  export { serializeJson } from "./serialize";
5
+ export * from "./nestedRoutes";
@@ -0,0 +1,18 @@
1
+ function sortByUrlPath(entries) {
2
+ entries.sort(function(a, b) {
3
+ const length1 = a.urlPath.length;
4
+ const length2 = b.urlPath.length;
5
+ if (length1 < length2) {
6
+ return 1;
7
+ }
8
+ if (length1 > length2) {
9
+ return -1;
10
+ }
11
+ return 0;
12
+ });
13
+ return entries;
14
+ }
15
+ export const matchEntry = (pathname, entries) => {
16
+ sortByUrlPath(entries);
17
+ return entries.find((entry) => pathname.startsWith(entry.urlPath));
18
+ };
@@ -5,4 +5,5 @@
5
5
  import type { IncomingHttpHeaders } from 'http';
6
6
  declare const run: <O>(context: IncomingHttpHeaders, cb: () => O | Promise<O>) => Promise<O>, useHeaders: () => IncomingHttpHeaders;
7
7
  export { run, useHeaders };
8
- export { serializeJson } from './serialize';
8
+ export { serializeJson } from './serialize';
9
+ export * from './nestedRoutes';
@@ -0,0 +1,3 @@
1
+ import type { ModernServerContext, ServerRoute } from '@modern-js/types';
2
+ export type ServerContext = Pick<ModernServerContext, 'logger' | 'req' | 'res' | 'params' | 'headers' | 'method' | 'url' | 'host' | 'protocol' | 'origin' | 'href' | 'path' | 'query'>;
3
+ export declare const matchEntry: (pathname: string, entries: ServerRoute[]) => ServerRoute | undefined;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.22.1-alpha.1",
18
+ "version": "2.22.1-alpha.3",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -241,8 +241,8 @@
241
241
  "webpack": "^5.82.1",
242
242
  "@types/serialize-javascript": "^5.0.1",
243
243
  "@modern-js/types": "2.22.0",
244
- "@scripts/build": "2.22.0",
245
- "@scripts/jest-config": "2.22.0"
244
+ "@scripts/jest-config": "2.22.0",
245
+ "@scripts/build": "2.22.0"
246
246
  },
247
247
  "sideEffects": false,
248
248
  "scripts": {
@@ -1 +0,0 @@
1
- "use strict";
File without changes
File without changes