This repository was archived by the owner on Aug 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.js
54 lines (47 loc) · 1.52 KB
/
functions.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//imports
const { team, root, admins } = require('./config');
function is_staff(ID) {
return team.includes(ID) ? true : false;
}
function is_root(ID) {
return root.includes(ID) ? true : false;
}
function is_admin(ID) {
return admins.includes(ID) ? true : false;
}
function generate_token(length) {
//edit the token allowed characters
var a =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'.split('');
var b = [];
for (var i = 0; i < length; i++) {
var j = (Math.random() * (a.length - 1)).toFixed(0);
b[i] = a[j];
}
return b.join('');
}
function is_url(str) {
let regexp =
/^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/;
if (regexp.test(str)) {
return true;
} else {
return false;
}
}
function formatNumbers(n) {
if (n < 1e3) return n;
if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(1) + 'K';
if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + 'M';
if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + 'B';
if (n >= 1e12) return +(n / 1e12).toFixed(1) + 'T';
}
//exports
module.exports = {
is_staff,
is_root,
is_admin,
generate_token,
is_url,
formatNumbers,
};