//#region node_modules/tldts-experimental/node_modules/tldts-core/dist/es6/src/is-ip.js
/**
* Check if a hostname is an IP. You should be aware that this only works
* because `hostname` is already garanteed to be a valid hostname!
*/
function isProbablyIpv4(hostname) {
	if (hostname.length < 7) return false;
	if (hostname.length > 15) return false;
	let numberOfDots = 0;
	for (let i = 0; i < hostname.length; i += 1) {
		const code = hostname.charCodeAt(i);
		if (code === 46) numberOfDots += 1;
		else if (code < 48 || code > 57) return false;
	}
	return numberOfDots === 3 && hostname.charCodeAt(0) !== 46 && hostname.charCodeAt(hostname.length - 1) !== 46;
}
/**
* Similar to isProbablyIpv4.
*/
function isProbablyIpv6(hostname) {
	if (hostname.length < 3) return false;
	let start = hostname.startsWith("[") ? 1 : 0;
	let end = hostname.length;
	if (hostname[end - 1] === "]") end -= 1;
	if (end - start > 39) return false;
	let hasColon = false;
	for (; start < end; start += 1) {
		const code = hostname.charCodeAt(start);
		if (code === 58) hasColon = true;
		else if (!(code >= 48 && code <= 57 || code >= 97 && code <= 102 || code >= 65 && code <= 70)) return false;
	}
	return hasColon;
}
/**
* Check if `hostname` is *probably* a valid ip addr (either ipv6 or ipv4).
* This *will not* work on any string. We need `hostname` to be a valid
* hostname.
*/
function isIp(hostname) {
	return isProbablyIpv6(hostname) || isProbablyIpv4(hostname);
}
//#endregion
export { isIp as default };
