const IPV4_ADDRESS_REGEX = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
const IPV6_ADDRESS_HOSTNAME_REGEX = /^\[[a-fA-F0-9:]*:[a-fA-F0-9:]*\]$/;
const IP_ADDRESS_HOSTNAME_REGEX = new RegExp(
  `(${IPV4_ADDRESS_REGEX.source}|${IPV6_ADDRESS_HOSTNAME_REGEX.source})`
);
function shouldEnableAnalytics(server, enableAnalytics = true) {
  if (!enableAnalytics) {
    return false;
  }
  const serverURL = server === null ? null : new URL(server);
  const socketHostname = serverURL?.hostname;
  return server !== null && socketHostname !== void 0 && socketHostname !== "localhost" && !IP_ADDRESS_HOSTNAME_REGEX.test(socketHostname);
}
export {
  IP_ADDRESS_HOSTNAME_REGEX,
  shouldEnableAnalytics
};
//# sourceMappingURL=enable-analytics.js.map
