-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUrlValidator.js
More file actions
33 lines (31 loc) · 1.07 KB
/
UrlValidator.js
File metadata and controls
33 lines (31 loc) · 1.07 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
const youTubeRegEx = /(http(s)?:\/\/)?((w){3}.)?youtu(?:be\.com\/watch\?.*v=|\.be\/)([\w\-\_]*)(&(amp;)?[\w\?=]*)?/;
const instagramRegEx = /(http(s)?:\/\/)?((w){3}.)?instagram\.com(\/p\/\w+\/?)/;
const spotifyRegEx = /spotify:track:\w+|(http(s)?:\/\/)?((w){3}.)?[a-z]+\.spotify\.com\/[^\s]+/;
const vliveRegEx = /(http(s)?:\/\/)?((w){3}.)?vlive\.tv\/video\/\d+/;
const twitterRegEx = /(http(s)?:\/\/)?((w){3}.)?twitter\.com\/[^\s]+/;
const redditRegEx = /(http(s)?:\/\/)?((w){3}.)?reddit\.com\/(r|user)\/[^\s]+/;
function matchStr(str, regex) {
if (str) {
return str.match(regex);
}
}
module.exports = {
matchYTUrl: function(url) {
return matchStr(url, youTubeRegEx);
},
matchIGUrl: function(url) {
return matchStr(url, instagramRegEx);
},
matchSpotifyUrl: function(url) {
return matchStr(url, spotifyRegEx);
},
matchVLiveUrl: function(url) {
return matchStr(url, vliveRegEx);
},
matchTwitterUrl: function(url) {
return matchStr(url, twitterRegEx);
},
matchRedditUrl: function(url) {
return matchStr(url, redditRegEx);
},
};