-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
constants.ts
79 lines (73 loc) · 2.48 KB
/
constants.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
export const CONSTANTS = {
REGEX_VALID_URL: new RegExp(
"^" +
// protocol identifier
"(?:(?:https?|ftp)://)" +
// user:pass authentication
"(?:\\S+(?::\\S*)?@)?" +
"(?:" +
// IP address exclusion
// private & local networks
"(?!(?: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})" +
// IP address dotted notation octets
// excludes loopback network 0.0.0.0
// excludes reserved space >= 224.0.0.0
// excludes network & broacast addresses
// (first & last IP address of each class)
"(?:[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]))" +
"|" +
// host name
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
// domain name
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
// TLD identifier
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
// TLD may end with dot
"\\.?" +
")" +
// port number
"(?::\\d{2,5})?" +
// resource path
"(?:[/?#]\\S*)?" +
"$",
"i"
),
REGEX_LOOPBACK: new RegExp(
"^" +
// Loopback: 127.0.0.0 - 127.255.255.255
"(?:127(?:\\.\\d{1,3}){3})" +
"|" +
// Private Class A: 10.0.0.0 - 10.255.255.255
"(?:10(?:\\.\\d{1,3}){3})" +
"|" +
// Private Class B: 172.16.0.0 - 172.31.255.255
"(?:172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
"|" +
// Private Class C: 192.168.0.0 - 192.168.255.255
"(?:192\\.168(?:\\.\\d{1,3}){2})" +
"|" +
// Link-local: 169.254.0.0 - 169.254.255.255
"(?:169\\.254(?:\\.\\d{1,3}){2})" +
"|" +
// Documentation: 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24
"(?:192\\.0\\.2(?:\\.\\d{1,3}){1})" +
"|" +
"(?:198\\.51\\.100(?:\\.\\d{1,3}){1})" +
"|" +
"(?:203\\.0\\.113(?:\\.\\d{1,3}){1})" +
"|" +
// Carrier-Grade NAT (CGNAT): 100.64.0.0 - 100.127.255.255
"(?:100\\.(?:6[4-9]|[7-9]\\d|1[0-1]\\d)(?:\\.\\d{1,3}){2})" +
"$",
"i"
),
REGEX_CONTENT_TYPE_IMAGE: new RegExp("image/.*", "i"),
REGEX_CONTENT_TYPE_AUDIO: new RegExp("audio/.*", "i"),
REGEX_CONTENT_TYPE_VIDEO: new RegExp("video/.*", "i"),
REGEX_CONTENT_TYPE_TEXT: new RegExp("text/.*", "i"),
REGEX_CONTENT_TYPE_APPLICATION: new RegExp("application/.*", "i"),
};