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.

index.js 713B

12345678910111213141516171819202122
  1. 'use strict';
  2. var ipRegex = require('ip-regex');
  3. module.exports = function (opts) {
  4. opts = opts || {};
  5. var protocol = '(?:(?:[a-z]+:)?//)';
  6. var auth = '(?:\\S+(?::\\S*)?@)?';
  7. var ip = ipRegex.v4().source;
  8. var host = '(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)';
  9. var domain = '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*';
  10. var tld = '(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))';
  11. var port = '(?::\\d{2,5})?';
  12. var path = '(?:[/?#][^\\s"]*)?';
  13. var regex = [
  14. '(?:' + protocol + '|www\\.)' + auth, '(?:localhost|' + ip + '|' + host + domain + tld + ')',
  15. port, path
  16. ].join('');
  17. return opts.exact ? new RegExp('(?:^' + regex + '$)', 'i') :
  18. new RegExp(regex, 'ig');
  19. };