forked from jmatsu/vector-drawable-previewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background_helper.ts
41 lines (35 loc) · 974 Bytes
/
background_helper.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
import RemoteMessageType from "./remote_message_type";
type Detector = (url: string) => RemoteMessageType | null;
const isLocalFile: Detector = (url) => {
if (/file?:\/\/\/.+\.xml\??.*$/.test(url)) {
return RemoteMessageType.GitHubBlob;
} else {
return null;
}
};
const isGitHubBlob: Detector = (url) => {
if (
/https?:\/\/github\.com\/[^/]+\/[^/]+\/blob\/.+?\/res\/[^/]+\/[^.]+\.xml\??.*$/.test(
url
)
) {
return RemoteMessageType.GitHubBlob;
} else {
return null;
}
};
const isGitHubDiff: Detector = (url) => {
if (/https?:\/\/github\.com\/[^/]+\/[^/]+\/pull\/[0-9]+\/files/.test(url)) {
return RemoteMessageType.GitHubDiff;
} else {
return null;
}
};
const isGitHubRaw: Detector = (url) => {
if (/https?:\/\/raw\.githubusercontent\.com\/.+\.xml\??.*$/.test(url)) {
return RemoteMessageType.GitHubRaw;
} else {
return null;
}
};
export { isGitHubBlob, isGitHubDiff, isGitHubRaw, isLocalFile };