thedesk/app/node_modules/url-regex/index.js

23 lines
713 B
JavaScript
Raw Normal View History

2018-02-19 04:41:25 +11:00
'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');
};