blob: 7498342b6e5d9b4a29ca1211711babb3257e1de1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import * as _ from 'lodash';
import { scroller } from 'react-scroll';
import { constants } from './constants';
export const utils = {
setUrlHash(anchorId: string) {
window.location.hash = anchorId;
},
scrollToHash(hash: string, containerId: string): void {
let finalHash = hash;
if (_.isEmpty(hash)) {
finalHash = constants.SCROLL_TOP_ID; // scroll to the top
}
scroller.scrollTo(finalHash, {
duration: 0,
offset: 0,
containerId,
});
},
getIdFromName(name: string) {
const id = name.replace(/ /g, '-');
return id;
},
getCurrentBaseUrl() {
const port = window.location.port;
const hasPort = !_.isUndefined(port);
const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`;
return baseUrl;
},
};
|