Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Check the port, if the suggest url has defined it.
if (suggestedUrlObject.port) {
if (urlObject.port !== suggestedUrlObject.port) {
return false;
}
}
// Perfect match.
if (urlObject.hostname === suggestedUrlObject.hostname) {
return true;
}
// If IPs, make a strict comparison.
const urlIsIpAddress = ipRegex({exact: true}).test(urlObject.hostname);
const suggestUrlIsIpAddress = ipRegex({exact: true}).test(suggestedUrlObject.hostname);
if (urlIsIpAddress || suggestUrlIsIpAddress) {
return urlObject.hostname === suggestedUrlObject.hostname;
}
// Otherwise check if the suggested url hostname is a parent host of the url hostname.
return isParentHostname(suggestedUrlObject.hostname, urlObject.hostname);
}
function isValidIp (ip) {
return ipRegex({ exact: true }).test(ip)
}
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);
}
} else if (
typeof options.sitemap !== "string" &&
!Array.isArray(options.sitemap)
) {
throw new Error(
"Option `sitemap` should be a string or an array"
);
}
}
if (options.host) {
if (typeof options.host !== "string") {
throw new Error("Options `host` must be only one string");
}
if (ipRegex({ exact: true }).test(options.host)) {
throw new Error("Options `host` should be not an IP address");
}
}
let contents = "";
options.policy.forEach((item, index) => {
contents += generatePoliceItem(item, index);
});
if (options.sitemap) {
contents += addLine("Sitemap", options.sitemap);
}
if (options.host) {
let normalizeHost = options.host;
isValidIP(candidate) {
return ipRegex({exact: true}).test(candidate);
}