Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ip.v6 = function (str) {
return ipRegex.v6({exact: true}).test(str);
};
isIp.v6 = string => ipRegex.v6({exact: true}).test(string);
isIp.version = string => isIp(string) ? (isIp.v4(string) ? 4 : 6) : undefined;
function hasV6IP(peers) {
for (let p of peers) {
if (ipRegex.v6({exact: true}).test(p.ip)) {
return true;
}
}
return false;
}
export default function isIp (value: string, type?: IpTypes): boolean {
if (type === 'v4') {
return ipRegex.v4({ exact: true }).test(value);
} else if (type === 'v6') {
return ipRegex.v6({ exact: true }).test(value);
}
return ipRegex({ exact: true }).test(value);
}
isIp.v6 = x => ipRegex.v6({exact: true}).test(x);
"use strict";
const ipRegex = require("ip-regex");
const v4 = ipRegex.v4().source + "\\/(3[0-2]|[12]?[0-9])";
const v6 = ipRegex.v6().source + "\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])";
const cidr = module.exports = opts => opts && opts.exact ?
new RegExp(`(?:^${v4}$)|(?:^${v6}$)`) :
new RegExp(`(?:${v4})|(?:${v6})`, "g");
cidr.v4 = opts => opts && opts.exact ? new RegExp(`^${v4}$`) : new RegExp(v4, "g");
cidr.v6 = opts => opts && opts.exact ? new RegExp(`^${v6}$`) : new RegExp(v6, "g");