source: trip-planner-front/node_modules/istanbul-reports/lib/html-spa/src/routing.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1exports.setLocation = function setLocation(
2 isReplace,
3 activeSort,
4 isFlat,
5 activeFilters,
6 fileFilter,
7 expandedLines
8) {
9 const params = [
10 activeSort.sortKey,
11 activeSort.order,
12 isFlat,
13 activeFilters.low,
14 activeFilters.medium,
15 activeFilters.high,
16 encodeURIComponent(fileFilter),
17 expandedLines.map(encodeURIComponent).join(',')
18 ];
19 const newUrl = `#${params.join('/')}`;
20
21 if (newUrl === location.hash) {
22 return;
23 }
24
25 window.history[isReplace ? 'replaceState' : 'pushState'](null, '', newUrl);
26};
27
28exports.decodeLocation = function decodeLocation() {
29 const items = location.hash.substr(1).split('/');
30 if (items.length !== 8) {
31 return null;
32 }
33
34 try {
35 return {
36 activeSort: {
37 sortKey: items[0],
38 order: items[1]
39 },
40 isFlat: JSON.parse(items[2]),
41 activeFilters: {
42 low: JSON.parse(items[3]),
43 medium: JSON.parse(items[4]),
44 high: JSON.parse(items[5])
45 },
46 fileFilter: decodeURIComponent(items[6]),
47 expandedLines: items[7].split(',').map(decodeURIComponent)
48 };
49 } catch (e) {
50 return null;
51 }
52};
Note: See TracBrowser for help on using the repository browser.