Debian Codegraph @

istanbul-reports/lib/html-spa/src/routing.js

raw symbols SCIP
1 exports.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
28 exports.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 };