soseki 0.0.9 → 0.0.11

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 (39) hide show
  1. package/dist/src/core/_process-routes.d.ts.map +1 -1
  2. package/dist/src/core/_process-routes.js +8 -10
  3. package/dist/src/core/_regexparam.d.ts +37 -0
  4. package/dist/src/core/_regexparam.d.ts.map +1 -0
  5. package/dist/src/core/_regexparam.js +1 -0
  6. package/dist/src/core/errors.d.ts +29 -0
  7. package/dist/src/core/errors.d.ts.map +1 -1
  8. package/dist/src/core/errors.js +20 -1
  9. package/dist/src/core/match-routes.d.ts +2 -2
  10. package/dist/src/core/match-routes.d.ts.map +1 -1
  11. package/dist/src/core/match-routes.js +4 -6
  12. package/dist/src/core/route-pattern-utils.d.ts +163 -0
  13. package/dist/src/core/route-pattern-utils.d.ts.map +1 -0
  14. package/dist/src/core/route-pattern-utils.js +222 -0
  15. package/dist/src/core/route.types.d.ts +27 -65
  16. package/dist/src/core/route.types.d.ts.map +1 -1
  17. package/dist/src/core/start-action.d.ts.map +1 -1
  18. package/dist/src/engines/navigation-api-engine.d.ts.map +1 -1
  19. package/dist/src/engines/navigation-api-engine.js +7 -9
  20. package/dist/src/hooks/use-params.d.ts +2 -2
  21. package/dist/src/hooks/use-params.d.ts.map +1 -1
  22. package/dist/src/soseki.d.ts +2 -0
  23. package/dist/src/soseki.d.ts.map +1 -1
  24. package/dist/src/soseki.js +1 -0
  25. package/package.json +1 -1
  26. package/src/core/_process-routes.ts +7 -12
  27. package/src/core/_regexparam.ts +67 -0
  28. package/src/core/errors.ts +52 -0
  29. package/src/core/match-routes.ts +6 -9
  30. package/src/core/route-pattern-utils.ts +327 -0
  31. package/src/core/route.types.ts +29 -98
  32. package/src/core/start-action.ts +2 -2
  33. package/src/engines/navigation-api-engine.ts +7 -9
  34. package/src/hooks/use-params.ts +3 -3
  35. package/src/soseki.ts +3 -0
  36. package/dist/src/core/_match-route-path.d.ts +0 -22
  37. package/dist/src/core/_match-route-path.d.ts.map +0 -1
  38. package/dist/src/core/_match-route-path.js +0 -26
  39. package/src/core/_match-route-path.ts +0 -45
@@ -1,26 +0,0 @@
1
- /**
2
- * 指定されたルートの正規表現パターンと URL のパス部分を照合し、マッチング検証およびパラメーター抽出を行う関数です。
3
- *
4
- * ルーティングエンジンが、現在の遷移先 URL に適合するルートを特定し、動的セグメントの値を型安全に回収する目的で使用します。
5
- *
6
- * @param route 検証対象となるルートオブジェクトから、マッチングに必要な `paramKeys` と `pathPattern` を抽出したオブジェクトです。
7
- * @param url マッチングの判定元となる、読み取り専用の URL オブジェクトです。
8
- * @returns マッチした場合は抽出されたパラメーターを含む `MatchPathResult` を返し、マッチしなかった場合は `null` を返します。
9
- */
10
- export default function matchPath(route, url) {
11
- const matches = route.pathPattern.exec(url.pathname);
12
- if (!matches) {
13
- return null;
14
- }
15
- const params = {};
16
- for (let i = 0, param; i < route.paramKeys.length; i++) {
17
- // exec メソッドの戻り値のインデックス 0 にはマッチした文字列全体が格納されているため、各パラメーターの値はインデックス 1 以降(i + 1)から取得します。
18
- param = matches[i + 1];
19
- // キャプチャーされたセグメントが存在し、かつ文字列型である場合にのみ、対応するパラメーターキーと値をマッピングします。
20
- // オプショナルなパラメーターが URL 側で省略されている場合は undefined となるため、この条件節により除外されます。
21
- if (typeof param === "string") {
22
- params[route.paramKeys[i]] = param;
23
- }
24
- }
25
- return { params };
26
- }
@@ -1,45 +0,0 @@
1
- import type { ReadonlyURL } from "./readonly-url.types.js";
2
- import type { Route, RoutePathParams } from "./route.types.js";
3
-
4
- /**
5
- * パスマッチングの処理結果を表すオブジェクトの型定義です。
6
- */
7
- export type MatchPathResult = {
8
- /**
9
- * マッチした URL パスから抽出されたパラメーターのキーと値のオブジェクトです。
10
- */
11
- params: RoutePathParams;
12
- };
13
-
14
- /**
15
- * 指定されたルートの正規表現パターンと URL のパス部分を照合し、マッチング検証およびパラメーター抽出を行う関数です。
16
- *
17
- * ルーティングエンジンが、現在の遷移先 URL に適合するルートを特定し、動的セグメントの値を型安全に回収する目的で使用します。
18
- *
19
- * @param route 検証対象となるルートオブジェクトから、マッチングに必要な `paramKeys` と `pathPattern` を抽出したオブジェクトです。
20
- * @param url マッチングの判定元となる、読み取り専用の URL オブジェクトです。
21
- * @returns マッチした場合は抽出されたパラメーターを含む `MatchPathResult` を返し、マッチしなかった場合は `null` を返します。
22
- */
23
- export default function matchPath(
24
- route: Pick<Route, "paramKeys" | "pathPattern">,
25
- url: ReadonlyURL,
26
- ): MatchPathResult | null {
27
- const matches = route.pathPattern.exec(url.pathname);
28
- if (!matches) {
29
- return null;
30
- }
31
-
32
- const params: Record<string, string> = {};
33
- for (let i = 0, param: string | undefined; i < route.paramKeys.length; i++) {
34
- // exec メソッドの戻り値のインデックス 0 にはマッチした文字列全体が格納されているため、各パラメーターの値はインデックス 1 以降(i + 1)から取得します。
35
- param = matches[i + 1];
36
-
37
- // キャプチャーされたセグメントが存在し、かつ文字列型である場合にのみ、対応するパラメーターキーと値をマッピングします。
38
- // オプショナルなパラメーターが URL 側で省略されている場合は undefined となるため、この条件節により除外されます。
39
- if (typeof param === "string") {
40
- params[route.paramKeys[i]!] = param;
41
- }
42
- }
43
-
44
- return { params };
45
- }