aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-tools-pages/ts/utils/utils.ts
blob: b274706a2bc867f4ba8c499246f2134e70b96ffa (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 bowser from 'bowser';
import * as _ from 'lodash';

export const utils = {
    getColSize(items: number): number {
        const bassCssGridSize = 12; // Source: http://basscss.com/#basscss-grid
        const colSize = bassCssGridSize / items;
        if (!_.isInteger(colSize)) {
            throw new Error(`Number of cols must be divisible by ${bassCssGridSize}`);
        }
        return colSize;
    },
    getCurrentBaseUrl(): string {
        const port = window.location.port;
        const hasPort = !_.isUndefined(port);
        const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`;
        return baseUrl;
    },
    onPageLoadPromise: new Promise<void>((resolve, _reject) => {
        if (document.readyState === 'complete') {
            resolve();
            return;
        }
        window.onload = () => resolve();
    }),
    openUrl(url: string): void {
        window.open(url, '_blank');
    },
    isMobileOperatingSystem(): boolean {
        return bowser.mobile;
    },
};