How to use the ip-regex function in ip-regex

To help you get started, we’ve selected a few ip-regex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github passbolt / passbolt_browser_extension / src / all / data / js / quickaccess / popup / components / HomePage / canSuggestUrl.js View on Github external
// 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);
}
github dev-mastery / comments-api / src / comment / index.js View on Github external
function isValidIp (ip) {
  return ipRegex({ exact: true }).test(ip)
}
github polkadot-js / common / packages / util / src / is / ip.ts View on Github external
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);
}
github itgalaxy / generate-robotstxt / src / standalone.js View on Github external
} 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;
github ambrosus / ambrosus-nop / src / services / validations.js View on Github external
isValidIP(candidate) {
    return ipRegex({exact: true}).test(candidate);
  }

ip-regex

Regular expression for matching IP addresses (IPv4 & IPv6)

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis

Popular ip-regex functions