anu-verzum 1.4.0 → 1.5.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/README.md +34 -0
- package/dist/core/components/History.d.ts +2 -0
- package/dist/core/components/History.js +40 -1
- package/dist/index.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -193,6 +193,9 @@ npm run format # Format all source files with Prettier
|
|
|
193
193
|
<li>
|
|
194
194
|
<a href="#redirecting-with-history-goto">Redirecting with Anu.History.goTo()</a>
|
|
195
195
|
</li>
|
|
196
|
+
<li>
|
|
197
|
+
<a href="#reading-url-parameters">Reading URL parameters</a>
|
|
198
|
+
</li>
|
|
196
199
|
</ul>
|
|
197
200
|
<li>
|
|
198
201
|
<a href="#server-api">Calling the server asynchronously - The Server API</a>
|
|
@@ -1316,6 +1319,37 @@ when you want to imperatively modify a child outside of the typical dataflow.
|
|
|
1316
1319
|
Anu.History.goTo('/about', true);
|
|
1317
1320
|
```
|
|
1318
1321
|
|
|
1322
|
+
<h3 id="reading-url-parameters">Reading URL parameters - <strong><code>Anu.History.getUrlParams()</code> and <code>Anu.History.getAllUrlParamNames()</code></strong></h3>
|
|
1323
|
+
|
|
1324
|
+
URLs are expected to follow the REST resource-path convention:
|
|
1325
|
+
|
|
1326
|
+
```
|
|
1327
|
+
/{noun-plural}/{id}/{noun-plural}/{id}/...
|
|
1328
|
+
```
|
|
1329
|
+
|
|
1330
|
+
The router parses the current pathname into named parameters by singularizing each noun segment and appending `Id`.
|
|
1331
|
+
A trailing action segment (odd-length path) is ignored.
|
|
1332
|
+
|
|
1333
|
+
| URL | Extracted params |
|
|
1334
|
+
|---|---|
|
|
1335
|
+
| `/products` | `{}` |
|
|
1336
|
+
| `/products/a3f8c2d1` | `{ productId: 'a3f8c2d1' }` |
|
|
1337
|
+
| `/users/asdf1234/products` | `{ userId: 'asdf1234' }` |
|
|
1338
|
+
| `/users/asdf1234/products/ghjk5678` | `{ userId: 'asdf1234', productId: 'ghjk5678' }` |
|
|
1339
|
+
| `/users/asdf1234/products/ghjk5678/delete` | `{ userId: 'asdf1234', productId: 'ghjk5678' }` |
|
|
1340
|
+
|
|
1341
|
+
- **`Anu.History.getUrlParams(key)`** — returns the value of the named URL parameter derived from the current pathname, or `null` if the key is not present.
|
|
1342
|
+
- **`Anu.History.getAllUrlParamNames()`** — returns an array of all parameter key names extractable from the current pathname. Useful for development and debugging.
|
|
1343
|
+
|
|
1344
|
+
```typescript
|
|
1345
|
+
// URL: /users/asdf1234/products/ghjk5678
|
|
1346
|
+
Anu.History.getUrlParams('userId'); // → 'asdf1234'
|
|
1347
|
+
Anu.History.getUrlParams('productId'); // → 'ghjk5678'
|
|
1348
|
+
Anu.History.getUrlParams('orderId'); // → null
|
|
1349
|
+
|
|
1350
|
+
Anu.History.getAllUrlParamNames(); // → ['userId', 'productId']
|
|
1351
|
+
```
|
|
1352
|
+
|
|
1319
1353
|
<br>
|
|
1320
1354
|
|
|
1321
1355
|
<h2 id="server-api">Calling the server asynchronously - <strong>The Server API</strong></h2>
|
|
@@ -68,6 +68,38 @@ const matchPath = (pathname, options) => {
|
|
|
68
68
|
isExact
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
|
+
const singularize = word => {
|
|
72
|
+
if (word.endsWith('ies')) {
|
|
73
|
+
return `${word.slice(0, -3)}y`;
|
|
74
|
+
}
|
|
75
|
+
if (word.endsWith('sses')) {
|
|
76
|
+
return word.slice(0, -2);
|
|
77
|
+
}
|
|
78
|
+
if (word.endsWith('xes')) {
|
|
79
|
+
return word.slice(0, -2);
|
|
80
|
+
}
|
|
81
|
+
if (word.endsWith('zes')) {
|
|
82
|
+
return word.slice(0, -3);
|
|
83
|
+
}
|
|
84
|
+
if (word.endsWith('ches')) {
|
|
85
|
+
return word.slice(0, -2);
|
|
86
|
+
}
|
|
87
|
+
if (word.endsWith('shes')) {
|
|
88
|
+
return word.slice(0, -2);
|
|
89
|
+
}
|
|
90
|
+
if (word.endsWith('s')) {
|
|
91
|
+
return word.slice(0, -1);
|
|
92
|
+
}
|
|
93
|
+
return word;
|
|
94
|
+
};
|
|
95
|
+
const parseUrlParams = pathname => {
|
|
96
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
97
|
+
const params = {};
|
|
98
|
+
for (let i = 0; i < segments.length - 1; i += 2) {
|
|
99
|
+
params[`${singularize(segments[i])}Id`] = segments[i + 1];
|
|
100
|
+
}
|
|
101
|
+
return params;
|
|
102
|
+
};
|
|
71
103
|
class HistoryRoute extends _Component.Component {
|
|
72
104
|
constructor(props) {
|
|
73
105
|
super(props);
|
|
@@ -166,9 +198,16 @@ const goTo = (path = '/', replace) => {
|
|
|
166
198
|
}
|
|
167
199
|
};
|
|
168
200
|
exports.goTo = goTo;
|
|
201
|
+
const getUrlParams = key => {
|
|
202
|
+
const params = parseUrlParams(window.location.pathname);
|
|
203
|
+
return params[key] ?? null;
|
|
204
|
+
};
|
|
205
|
+
const getAllUrlParamNames = () => Object.keys(parseUrlParams(window.location.pathname));
|
|
169
206
|
const History = {
|
|
170
207
|
Link: HistoryLink,
|
|
171
208
|
Redirect: HistoryRedirect,
|
|
172
|
-
Route: HistoryRoute
|
|
209
|
+
Route: HistoryRoute,
|
|
210
|
+
getUrlParams,
|
|
211
|
+
getAllUrlParamNames
|
|
173
212
|
};
|
|
174
213
|
var _default = exports.default = History;
|
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,8 @@ declare const Anu: {
|
|
|
83
83
|
};
|
|
84
84
|
isAnuComponent?: boolean;
|
|
85
85
|
};
|
|
86
|
+
getUrlParams: (key: string) => string | null;
|
|
87
|
+
getAllUrlParamNames: () => string[];
|
|
86
88
|
};
|
|
87
89
|
Intl: {
|
|
88
90
|
abbreviateNumber: (value: number, options?: import(".").AbbreviateNumberOptions) => string | number;
|
package/package.json
CHANGED