is-url

A tiny, dependency-free JavaScript utility for loosely validating whether a string is a URL.

Library
npm
v1.2.4
168stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
41/100Fair
Development Activity12
Maintenance0
Community72
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture55
Code Quality65
Innovation80
Learning Curve90

is-url is a minimal JavaScript utility created by Segment that checks whether a given string looks like a URL. It exposes a single function, isUrl(string), that returns a boolean based on a lightweight regular-expression check covering protocol-relative URLs, localhost addresses, and standard domains.

Because it has zero runtime dependencies and a tiny footprint, it is commonly reached for in form validation, link-detection utilities, and content-sanitization pipelines where a full URL-parsing library would be overkill. The project is feature-complete and in maintenance mode, but remains a dependable building block for both Node.js and browser codebases.

What You Get

  • A single exported isUrl(string) function with no configuration required
  • Zero runtime dependencies and a sub-1KB implementation
  • Support for protocol-relative URLs (//example.com) and localhost addresses
  • Works identically in Node.js and browser environments

Common Use Cases

  • Validating user-submitted links in forms before persisting them
  • Filtering arrays of strings to detect which ones are links
  • Guarding link-rendering components (e.g. auto-linking chat or comment text) against non-URL input
  • Lightweight pre-checks before passing a value to a heavier URL parser

Under The Hood

Architecture - The entire package is a single CommonJS module (index.js) that exports one function, isUrl(string). Validation happens in two stages: a top-level regular expression (protocolAndDomainRE) strips an optional protocol and captures everything after //, then a second pair of regexes (localhostDomainRE, nonLocalhostDomainRE) checks whether the remainder looks like a localhost address or a standard host.tld domain. There is no internal state, no classes, and no configuration surface — the whole control flow is a handful of match/test calls. Tech Stack - The package has no runtime dependencies at all; mocha is the sole devDependency, used purely for the test suite. It ships as plain ES5 JavaScript with no build step, no TypeScript types, and no bundler configuration, keeping the published artifact identical to the source file. Code Quality - test/index.js exercises the function against a table of valid URLs (http, https, ftp, protocol-relative, localhost with port) and invalid strings (empty string, plain words, malformed protocols), giving reasonable behavioral coverage for such a small surface area, though there are no type definitions or edge-case tests for internationalized domains. Naming is terse but clear (isUrl, protocolAndDomainRE), and the code favors early returns over nested conditionals. API Design - The public API is a single function taking one string argument and returning a boolean, which makes adoption essentially zero-friction — there is nothing to configure, no options object, and the README documents the entire contract in a few lines.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search