This repository was archived by the owner on Mar 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathUrl.js
More file actions
50 lines (50 loc) · 1.52 KB
/
Url.js
File metadata and controls
50 lines (50 loc) · 1.52 KB
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
export class UrlUtils {
static isRemoteUrl(url) {
return url && /^(((http)s*)|(ftp)):/.test(url);
}
static isEncodedData(url) {
return (url && /^data:/.test(url)) || (url && /^file:/.test(url));
}
static isSvgXml(url) {
return url && /(^data:image\/svg\+xml)|(\.svg$)/.test(url);
}
static isDeepLink(url) {
return url && /^[\w]+:\/\//.test(url) && !UrlUtils.isRemoteUrl(url) && !UrlUtils.isEncodedData(url);
}
static isRelativeUrl(url) {
return url && !UrlUtils.isRemoteUrl(url) && !UrlUtils.isEncodedData(url) && !UrlUtils.isDeepLink(url);
}
static composeUrl(base, path) {
if (base && base.length > 0 && path && path.length > 0) {
if (base[base.length - 1] === '/') {
if (path[0] === '/') {
return base + path.slice(1);
}
else {
return base + path;
}
}
else {
if (path[0] === '/') {
return base + path;
}
else {
return base.slice(base.length - 1) + path;
}
}
}
if (base && base.length > 0) {
return base;
}
if (path && path.length > 0) {
return path;
}
return '';
}
static toAbsolute(url, host) {
if (UrlUtils.isRelativeUrl(url)) {
return UrlUtils.composeUrl(host, url);
}
return url;
}
}