is-ip
A tiny, focused utility to check whether a string is a valid IPv4 or IPv6 address.
Repository Health
Technical Analysis
is-ip is a minimal JavaScript utility that checks whether a string is a valid IP address. It exposes simple predicates for IPv4, IPv6, or either, plus a helper that returns the detected IP version, all backed by strict, anchored regular expressions.
Part of Sindre Sorhus’s widely used utility ecosystem, is-ip is an ES module with no reliance on Node’s built-ins, so it works in browsers and other runtimes as well as Node.js. It is a common building block for validation, routing, and networking code.
What You Get
isIP,isIPv4, andisIPv6predicates for boolean IP validation.ipVersionhelper that returns 6, 4, or undefined.- An ES module that runs in browsers and non-Node runtimes, not just Node.js.
- Strict, fully anchored matching that rejects partial or embedded IPs.
Common Use Cases
- Validating user- or config-supplied host values before using them.
- Branching logic based on whether an address is IPv4 or IPv6.
- Sanitizing input in networking, proxy, or routing code.
Under The Hood
Architecture
The entire module is index.js: it imports strict IPv4 and IPv6 patterns from ip-regex and super-regex (for ReDoS-safe execution), anchors them, and exposes isIP, isIPv4, isIPv6, and ipVersion as thin wrappers that run a single test/match against the input string.
Tech Stack
Modern JavaScript ES module targeting Node.js >=14.16 and browsers, depending only on ip-regex for the address patterns and super-regex for safe regex execution. Types are hand-written in index.d.ts; testing uses AVA, xo, and tsd.
Code Quality
Despite its size the package is rigorously tested: test.js (AVA), index.test-d.ts (tsd type tests), and xo linting all run in the test script. TypeScript definitions are shipped, and the single-file implementation keeps the surface trivial to audit.
API Design
The API is about as ergonomic as possible: named exports that each take one string and return a boolean (or version number). There is no configuration, no options object, and no setup, so adoption is instant and the README documents every function with examples.