-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathtooltip_utils.ts
More file actions
38 lines (33 loc) · 1.09 KB
/
tooltip_utils.ts
File metadata and controls
38 lines (33 loc) · 1.09 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
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// Regex to match if a URl is valid merge request of issue URL
const gitlabRegexPattern = /https?:\/\/(www\.)?.*\/([\w.?-]+)\/([\w-]+)\/-\/([\w-]+)\/([\d-]+$)/;
export const validateGitlabUrl = (url: string): boolean => {
return gitlabRegexPattern.test(url);
};
export const isValidUrl = (urlString: string): boolean => {
try {
return Boolean(new URL(urlString));
} catch {
return false;
}
};
export const getTruncatedText = (text: string, length: number): string => {
let truncatedText = text.substring(0, length).trim();
if (text.length > length) {
truncatedText += '...';
}
return truncatedText;
};
export const getInfoAboutLink = (href: string, hostname: string) => {
const linkInfo = href.split(`${hostname}/`)[1].split('/');
if (linkInfo.length >= 5) {
return {
owner: linkInfo[0],
repo: linkInfo[1],
type: linkInfo[3],
number: linkInfo[4],
};
}
return {};
};