UNPKG

727 BJavaScriptView Raw
1import { __values } from './_virtual/_tslib.js';
2import { matchesState } from './utils.js';
3
4function mapState(stateMap, stateId) {
5 var e_1, _a;
6
7 var foundStateId;
8
9 try {
10 for (var _b = __values(Object.keys(stateMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
11 var mappedStateId = _c.value;
12
13 if (matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
14 foundStateId = mappedStateId;
15 }
16 }
17 } catch (e_1_1) {
18 e_1 = {
19 error: e_1_1
20 };
21 } finally {
22 try {
23 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
24 } finally {
25 if (e_1) throw e_1.error;
26 }
27 }
28
29 return stateMap[foundStateId];
30}
31
32export { mapState };