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 669B

1234567891011121314151617181920
  1. 'use strict';
  2. var v4 = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}';
  3. var v6 = '(?:(?:[0-9a-fA-F:]){1,4}(?:(?::(?:[0-9a-fA-F]){1,4}|:)){2,7})+';
  4. var ip = module.exports = function (opts) {
  5. opts = opts || {};
  6. return opts.exact ? new RegExp('(?:^' + v4 + '$)|(?:^' + v6 + '$)') :
  7. new RegExp('(?:' + v4 + ')|(?:' + v6 + ')', 'g');
  8. };
  9. ip.v4 = function (opts) {
  10. opts = opts || {};
  11. return opts.exact ? new RegExp('^' + v4 + '$') : new RegExp(v4, 'g');
  12. };
  13. ip.v6 = function (opts) {
  14. opts = opts || {};
  15. return opts.exact ? new RegExp('^' + v6 + '$') : new RegExp(v6, 'g');
  16. };