-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutil.ts
More file actions
36 lines (30 loc) · 798 Bytes
/
util.ts
File metadata and controls
36 lines (30 loc) · 798 Bytes
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
import fs from "fs";
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
export function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
export function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
/**
* Get the content type of a URL
* @param url
*/
export function contentType(url : string) {
if (url.endsWith(".css")) {
return "text/css";
} else if (url.endsWith(".js")) {
return "text/javascript";
} else {
return "text/html";
}
}
export function fileExists(file : string) {
return fs.promises.access(file, fs.constants.F_OK)
.then(() => true)
.catch(() => false);
}