@thi.ng/router 3.3.0 → 3.4.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-03-09T16:05:59Z
3
+ - **Last updated**: 2024-03-10T13:28:34Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,16 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [3.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/router@3.4.0) (2024-03-10)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add defMatch() helper ([12134b6](https://github.com/thi-ng/umbrella/commit/12134b6))
17
+
18
+ #### 🩹 Bug fixes
19
+
20
+ - rebuild index in updateRoutes() ([deb494e](https://github.com/thi-ng/umbrella/commit/deb494e))
21
+
12
22
  ## [3.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/router@3.3.0) (2024-03-09)
13
23
 
14
24
  #### 🚀 Features
package/basic.d.ts CHANGED
@@ -37,4 +37,21 @@ export declare class BasicRouter implements INotify<RouterEventType> {
37
37
  protected validateRouteParams(params: any, validators: IObjectOf<Partial<RouteParamValidator>>): boolean;
38
38
  protected handleRouteFailure(): boolean;
39
39
  }
40
+ /**
41
+ * Helper function to define a {@link Route.match} array from a string pattern.
42
+ *
43
+ * @example
44
+ * ```ts tangle:../export/def-match.ts
45
+ * import { defMatch } from "@thi.ng/router";
46
+ *
47
+ * console.log(
48
+ * defMatch("/contacts/?id/friends")
49
+ * );
50
+ * // ["contacts", "?id", "friends"]
51
+ * ```
52
+ *
53
+ * @param pattern
54
+ * @param sep
55
+ */
56
+ export declare const defMatch: (pattern: string, sep?: string) => string[];
40
57
  //# sourceMappingURL=basic.d.ts.map
package/basic.js CHANGED
@@ -36,10 +36,6 @@ let BasicRouter = class {
36
36
  ...config
37
37
  };
38
38
  this.updateRoutes();
39
- this.routeIndex = this.config.routes.reduce(
40
- (acc, r) => (acc[r.id] = r, acc),
41
- {}
42
- );
43
39
  assert(
44
40
  this.routeForID(this.config.defaultRouteID) !== void 0,
45
41
  `missing config for default route: '${this.config.defaultRouteID}'`
@@ -150,6 +146,10 @@ let BasicRouter = class {
150
146
  acc[fmt] = true;
151
147
  return acc;
152
148
  }, {});
149
+ this.routeIndex = this.config.routes.reduce(
150
+ (acc, r) => (acc[r.id] = r, acc),
151
+ {}
152
+ );
153
153
  }
154
154
  matchRoutes(src) {
155
155
  const routes = this.config.routes;
@@ -203,6 +203,8 @@ BasicRouter = __decorateClass([
203
203
  ], BasicRouter);
204
204
  const isParametricRoute = (route) => route.match.some(isRouteParam);
205
205
  const isRouteParam = (x) => x[0] === "?";
206
+ const defMatch = (pattern, sep = "/") => pattern.split(sep).filter((x) => !!x);
206
207
  export {
207
- BasicRouter
208
+ BasicRouter,
209
+ defMatch
208
210
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/router",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Generic router for browser & non-browser based applications",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -92,5 +92,5 @@
92
92
  ],
93
93
  "year": 2014
94
94
  },
95
- "gitHead": "940dfa3d8157860608e7ee5d1230bd11d3630866\n"
95
+ "gitHead": "c93ab989dd2013dce1a7f7434f42ef3a270b950f\n"
96
96
  }