@lexriver/dome 2.0.4 → 2.0.5

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/README.md CHANGED
@@ -1507,9 +1507,9 @@ Parameters:
1507
1507
  Where `RouteAction` type is:
1508
1508
  ```typescript
1509
1509
  export type RouteAction = (
1510
- params:{[key:string]:string|number}, // parameters from url path
1511
- url:string, // url path without query string
1512
- scrollToPreviousPositionAsync:()=>Promise<void>, // this function can be called to scroll to previous page position
1510
+ params:{[key:string]:string}, // unannotated parameters from the URL path
1511
+ url:string, // URL path without query string
1512
+ scrollToPreviousPositionAsync:()=>Promise<void>, // call this to scroll to the previous page position
1513
1513
  query:{[key:string]:string} // query parameters from window.location.search
1514
1514
  ) => void|Promise<void>
1515
1515
  ```
@@ -1529,28 +1529,23 @@ DomeRouter.onRoute('/product/:productId', true, (params, url) => {
1529
1529
  })
1530
1530
  ```
1531
1531
 
1532
- A type of parameter can be added, for example :
1532
+ For numeric parameters, use `onTypedRoute`. This opt-in API types route values as `string | number`, because TypeScript 3.9 cannot infer parameter types from route-string annotations.
1533
+
1533
1534
  ```typescript
1534
- DomeRouter.onRoute('/product/:productId<number>', true, (params, url) => {
1535
- // for example for '/product/456' the output will be
1536
- // 'productId=', 456, number
1537
- console.log('productId=', params.productId, typeof params.productId)
1535
+ DomeRouter.onTypedRoute('/product/:productId<number>', true, (params, url) => {
1536
+ // For '/product/456', productId is 456 at runtime.
1537
+ if(typeof params.productId === 'number') {
1538
+ console.log('productId=', params.productId)
1539
+ }
1538
1540
  })
1539
1541
  ```
1540
1542
 
1541
- A possible types are:
1543
+ The supported numeric annotations are:
1542
1544
  * `int` - uses `parseInt(p)` internally
1543
1545
  * `float` - uses `parseFloat(p)` internally
1544
- * `number` - uses `Number(p)` intrenally
1545
- But there is no validation for paramters, so the result of specified function will be returned.
1546
+ * `number` - uses `Number(p)` internally
1546
1547
 
1547
- ```typescript
1548
- DomeRouter.onRoute('/product/:productId<int>', true, (params, url) => {
1549
- // for example for '/product/456' the output will be
1550
- // 'productId=', 456, number
1551
- console.log('productId=', params.productId, typeof params.productId)
1552
- })
1553
- ```
1548
+ There is no numeric validation, so the result of the corresponding conversion function is returned. Existing unannotated routes should continue using `onRoute`; their parameters remain strings without casts.
1554
1549
 
1555
1550
  <br/>
1556
1551
 
package/out/index.cjs CHANGED
@@ -887,12 +887,19 @@ var DomeRouter;
887
887
  executeAsync(url, getScrollPositionForUrl(url));
888
888
  }
889
889
  DomeRouter2.resolveUrl = resolveUrl;
890
- function onRoute(route, exactMatch, action) {
890
+ function addRoute(route, exactMatch, action) {
891
891
  if (route[0] !== "/") throw new Error("Please provide correct route. route=" + route);
892
- let routeSlices = getRouteSlices(route);
892
+ const routeSlices = getRouteSlices(route);
893
893
  allRoutes.push({ routeSlices, exactMatch, action });
894
894
  }
895
+ function onRoute(route, exactMatch, action) {
896
+ addRoute(route, exactMatch, action);
897
+ }
895
898
  DomeRouter2.onRoute = onRoute;
899
+ function onTypedRoute(route, exactMatch, action) {
900
+ addRoute(route, exactMatch, action);
901
+ }
902
+ DomeRouter2.onTypedRoute = onTypedRoute;
896
903
  function getRouteSlices(route) {
897
904
  return route.split("/").map((x) => decodeURIComponent(x));
898
905
  }
package/out/index.mjs CHANGED
@@ -2035,12 +2035,19 @@ var DomeRouter;
2035
2035
  executeAsync(url, getScrollPositionForUrl(url));
2036
2036
  }
2037
2037
  DomeRouter2.resolveUrl = resolveUrl;
2038
- function onRoute(route, exactMatch, action) {
2038
+ function addRoute(route, exactMatch, action) {
2039
2039
  if (route[0] !== "/") throw new Error("Please provide correct route. route=" + route);
2040
- let routeSlices = getRouteSlices(route);
2040
+ const routeSlices = getRouteSlices(route);
2041
2041
  allRoutes.push({ routeSlices, exactMatch, action });
2042
2042
  }
2043
+ function onRoute(route, exactMatch, action) {
2044
+ addRoute(route, exactMatch, action);
2045
+ }
2043
2046
  DomeRouter2.onRoute = onRoute;
2047
+ function onTypedRoute(route, exactMatch, action) {
2048
+ addRoute(route, exactMatch, action);
2049
+ }
2050
+ DomeRouter2.onTypedRoute = onTypedRoute;
2044
2051
  function getRouteSlices(route) {
2045
2052
  return route.split("/").map((x) => decodeURIComponent(x));
2046
2053
  }
@@ -1,8 +1,14 @@
1
- export type RouteAction = (params: {
1
+ export type RouteParameters = {
2
+ [key: string]: string;
3
+ };
4
+ export type TypedRouteParameters = {
2
5
  [key: string]: string | number;
3
- }, url: string, scrollToPreviousPositionAsync: () => Promise<void>, query: {
6
+ };
7
+ type RouteCallback<Parameters> = (params: Parameters, url: string, scrollToPreviousPositionAsync: () => Promise<void>, query: {
4
8
  [key: string]: string;
5
9
  }) => void | Promise<void>;
10
+ export type RouteAction = RouteCallback<RouteParameters>;
11
+ export type TypedRouteAction = RouteCallback<TypedRouteParameters>;
6
12
  export declare namespace DomeRouter {
7
13
  let maxHistoryUrlsCount: number;
8
14
  function navigate(url: string): void;
@@ -16,7 +22,10 @@ export declare namespace DomeRouter {
16
22
  */
17
23
  function getPreviousPageUrl(previousPageIndex?: number): string | undefined;
18
24
  function resolveUrl(url?: string, addToHistory?: boolean): void;
25
+ /** Register a route whose unannotated parameters are strings. */
19
26
  function onRoute(route: string, exactMatch: boolean, action: RouteAction): void;
27
+ /** Register a route using <int>, <float>, or <number> parameter annotations. */
28
+ function onTypedRoute(route: string, exactMatch: boolean, action: TypedRouteAction): void;
20
29
  function onNotFound(action: () => void): void;
21
30
  /**
22
31
  * Check if url matched route.
@@ -30,3 +39,4 @@ export declare namespace DomeRouter {
30
39
  */
31
40
  function checkUrlMatchRouteAndGetParameters(url: string, route: string, exactMatch?: boolean): Object | undefined;
32
41
  }
42
+ export {};
@@ -1,8 +1,14 @@
1
- export type RouteAction = (params: {
1
+ export type RouteParameters = {
2
+ [key: string]: string;
3
+ };
4
+ export type TypedRouteParameters = {
2
5
  [key: string]: string | number;
3
- }, url: string, scrollToPreviousPositionAsync: () => Promise<void>, query: {
6
+ };
7
+ type RouteCallback<Parameters> = (params: Parameters, url: string, scrollToPreviousPositionAsync: () => Promise<void>, query: {
4
8
  [key: string]: string;
5
9
  }) => void | Promise<void>;
10
+ export type RouteAction = RouteCallback<RouteParameters>;
11
+ export type TypedRouteAction = RouteCallback<TypedRouteParameters>;
6
12
  export declare namespace DomeRouter {
7
13
  let maxHistoryUrlsCount: number;
8
14
  function navigate(url: string): void;
@@ -16,7 +22,10 @@ export declare namespace DomeRouter {
16
22
  */
17
23
  function getPreviousPageUrl(previousPageIndex?: number): string | undefined;
18
24
  function resolveUrl(url?: string, addToHistory?: boolean): void;
25
+ /** Register a route whose unannotated parameters are strings. */
19
26
  function onRoute(route: string, exactMatch: boolean, action: RouteAction): void;
27
+ /** Register a route using <int>, <float>, or <number> parameter annotations. */
28
+ function onTypedRoute(route: string, exactMatch: boolean, action: TypedRouteAction): void;
20
29
  function onNotFound(action: () => void): void;
21
30
  /**
22
31
  * Check if url matched route.
@@ -30,3 +39,4 @@ export declare namespace DomeRouter {
30
39
  */
31
40
  function checkUrlMatchRouteAndGetParameters(url: string, route: string, exactMatch?: boolean): Object | undefined;
32
41
  }
42
+ export {};
@@ -88,13 +88,22 @@ export var DomeRouter;
88
88
  executeAsync(url, getScrollPositionForUrl(url));
89
89
  }
90
90
  DomeRouter.resolveUrl = resolveUrl;
91
- function onRoute(route, exactMatch, action) {
91
+ function addRoute(route, exactMatch, action) {
92
92
  if (route[0] !== '/')
93
93
  throw new Error('Please provide correct route. route=' + route);
94
- let routeSlices = getRouteSlices(route);
94
+ const routeSlices = getRouteSlices(route);
95
95
  allRoutes.push({ routeSlices, exactMatch, action });
96
96
  }
97
+ /** Register a route whose unannotated parameters are strings. */
98
+ function onRoute(route, exactMatch, action) {
99
+ addRoute(route, exactMatch, action);
100
+ }
97
101
  DomeRouter.onRoute = onRoute;
102
+ /** Register a route using <int>, <float>, or <number> parameter annotations. */
103
+ function onTypedRoute(route, exactMatch, action) {
104
+ addRoute(route, exactMatch, action);
105
+ }
106
+ DomeRouter.onTypedRoute = onTypedRoute;
98
107
  function getRouteSlices(route) {
99
108
  //return route.split('/').filter(x => x.length>0).map(x => decodeURIComponent(x))
100
109
  return route.split('/').map(x => decodeURIComponent(x));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "@lexriver/dome",
4
- "version": "2.0.4",
4
+ "version": "2.0.5",
5
5
  "description": "DOM manipulator",
6
6
  "type": "module",
7
7
  "types": "./out/src/index.d.ts",