You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
713 B
22 lines
713 B
'use strict'; |
|
var ipRegex = require('ip-regex'); |
|
|
|
module.exports = function (opts) { |
|
opts = opts || {}; |
|
|
|
var protocol = '(?:(?:[a-z]+:)?//)'; |
|
var auth = '(?:\\S+(?::\\S*)?@)?'; |
|
var ip = ipRegex.v4().source; |
|
var host = '(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)'; |
|
var domain = '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*'; |
|
var tld = '(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))'; |
|
var port = '(?::\\d{2,5})?'; |
|
var path = '(?:[/?#][^\\s"]*)?'; |
|
var regex = [ |
|
'(?:' + protocol + '|www\\.)' + auth, '(?:localhost|' + ip + '|' + host + domain + tld + ')', |
|
port, path |
|
].join(''); |
|
|
|
return opts.exact ? new RegExp('(?:^' + regex + '$)', 'i') : |
|
new RegExp(regex, 'ig'); |
|
};
|
|
|