Skip to content

Commit 412258f

Browse files
committed
utils: move static regex
1 parent 4a21293 commit 412258f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/utils.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const unescapeIRCRegex = /\\([sn:r\\])/g;
55
const escapeIRCRegex = /([ \n;\r\\])/g;
66
const ircEscapedChars = { s: ' ', n: '', ':': ';', r: '' };
77
const ircUnescapedChars = { ' ': 's', '\n': 'n', ';': ':', '\r': 'r' };
8+
const urlRegex = new RegExp('^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!(?: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})(?:[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]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))\\.?)(?::\\d{2,5})?(?:[/?#]\\S*)?$', 'i');
9+
const regexEmoteRegex = /[|\\^$*+?:#]/;
810
const _ = module.exports = {
911
// Return the second value if the first value is undefined..
1012
get: (a, b) => typeof a === 'undefined' ? b : a,
@@ -31,10 +33,10 @@ const _ = module.exports = {
3133
isInteger: int => !isNaN(_.toNumber(int, 0)),
3234

3335
// Value is a regex..
34-
isRegex: str => /[|\\^$*+?:#]/.test(str),
36+
isRegex: str => regexEmoteRegex.test(str),
3537

3638
// Value is a valid url..
37-
isURL: str => new RegExp('^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!(?: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})(?:[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]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))\\.?)(?::\\d{2,5})?(?:[/?#]\\S*)?$', 'i').test(str),
39+
isURL: str => urlRegex.test(str),
3840

3941
// Return a random justinfan username..
4042
justinfan: () => `justinfan${Math.floor((Math.random() * 80000) + 1000)}`,

0 commit comments

Comments
 (0)