-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.re
executable file
·35 lines (28 loc) · 1.2 KB
/
Utils.re
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
33
34
35
/* require css file for side effect only */
[@bs.val] external requireCSS: string => unit = "require";
/* require an asset (eg. an image) and return exported string value (image URI) */
[@bs.val] external requireAssetURI: string => string = "require";
[@bs.val] external currentTime: unit => int = "Date.now";
/* format a timestamp in seconds as relative humanised time sentence */
let fromNow = unixtime => {
let delta = currentTime() / 1000 - unixtime;
if (delta < 3600) {
string_of_int(delta / 60) ++ " minutes ago";
} else if (delta < 86400) {
string_of_int(delta / 3600) ++ " hours ago";
} else {
string_of_int(delta / 86400) ++ " days ago";
};
};
[@bs.send] [@bs.return nullable]
external getAttribute: (Js.t('a), string) => option(string) = "getAttribute";
let dangerousHtml: string => Js.t('a) = html => {"__html": html};
let distanceFromBottom: unit => int =
() => {
let bodyClientHeight = [%raw "document.body.clientHeight"];
let windowScrollY = [%raw "window.scrollY"];
let windowInnerHeight = [%raw "window.innerHeight"];
bodyClientHeight - (windowScrollY + windowInnerHeight);
};
[@bs.module]
external registerServiceWorker: unit => unit = "src/registerServiceWorker";