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

21 lines
669 B
JavaScript
Raw Normal View History

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