wishthis/node_modules/ip-regex/index.js
2022-01-21 09:28:41 +01:00

20 lines
669 B
JavaScript

'use strict';
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}';
var v6 = '(?:(?:[0-9a-fA-F:]){1,4}(?:(?::(?:[0-9a-fA-F]){1,4}|:)){2,7})+';
var ip = module.exports = function (opts) {
opts = opts || {};
return opts.exact ? new RegExp('(?:^' + v4 + '$)|(?:^' + v6 + '$)') :
new RegExp('(?:' + v4 + ')|(?:' + v6 + ')', 'g');
};
ip.v4 = function (opts) {
opts = opts || {};
return opts.exact ? new RegExp('^' + v4 + '$') : new RegExp(v4, 'g');
};
ip.v6 = function (opts) {
opts = opts || {};
return opts.exact ? new RegExp('^' + v6 + '$') : new RegExp(v6, 'g');
};