Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function ipTerm(node: Term) {
const argeCidr = isCidr(node.value as string);
if (argeCidr > 0) {
const range = ip6addr.createCIDR(node.value);
return pRangeTerm(range);
}
return function isIpterm(ip: string) {
if (isCidr(ip) > 0) {
const argRange = ip6addr.createCIDR(ip);
return argRange.contains(node.value);
}
return ip === node.value;
};
}
ipFn = (ip: string) => {
if (isCidr(ip) > 0) {
const argRange = ip6addr.createCIDR(ip);
const argFirst = argRange.first().toString();
const argLast = argRange.last().toString();
const rangeFirst = range.first().toString();
const rangeLast = range.last().toString();
return (range.contains(argFirst) || range.contains(argLast) || argRange.contains(rangeFirst) || argRange.contains(rangeLast));
}
if (isIP(ip) > 0) return range.contains(ip);
return false;
};
} else {
return function isIpterm(ip: string) {
if (isCidr(ip) > 0) {
const argRange = ip6addr.createCIDR(ip);
return argRange.contains(node.value);
}
return ip === node.value;
};
}
const populateIpQueries = (node: AST, _field?: string) => {
const topField = node.field || _field;
if (topField && this.fields[topField]) {
let ipFn;
if (node.term) {
const argeCidr = isCidr(node.term);
if (argeCidr > 0) {
const range = ip6addr.createCIDR(node.term);
ipFn = (ip: string) => {
if (isCidr(ip) > 0) {
const argRange = ip6addr.createCIDR(ip);
const argFirst = argRange.first().toString();
const argLast = argRange.last().toString();
const rangeFirst = range.first().toString();
const rangeLast = range.last().toString();
return (range.contains(argFirst) || range.contains(argLast) || argRange.contains(rangeFirst) || argRange.contains(rangeLast));
}
if (isIP(ip) > 0) return range.contains(ip);
return false;
};
} else {
return function checkIp(ip: string) {
if (isCidr(ip) > 0) {
return checkCidr(ip, range);
}
if (isIP(ip) > 0) return range.contains(ip);
return false;
};
}