url-parse

Small, dependency-light URL parser that works identically in Node.js and the browser.

Library
npm
v1.5.10
1,034stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
39/100Needs Attention
Development Activity0
Maintenance0
Community68
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture70
Code Quality74
Innovation50
Learning Curve85

url-parse takes a URL string and breaks it into its component parts — protocol, host, port, pathname, query, and hash — using a hand-written string-scanning parser rather than regular expressions or the DOM, so it runs identically in Node.js, browsers, and environments without DOM access like Web Workers.

It bundles the querystringify module for parsing and stringifying query strings and the requires-port module for protocol-aware port normalization, giving a self-contained URL toolkit historically used in environments (older browsers, Workers) that predate wide support for the native WHATWG URL interface.

What You Get

  • A Url constructor/function that parses a URL string (absolute or relative, with an optional base) into protocol/host/port/pathname/query/hash fields
  • Bundled query-string parsing and stringification via the companion querystringify module
  • Protocol-aware default port handling through the requires-port module
  • A set() method for mutating individual URL parts and re-serializing the whole URL
  • Consistent behavior across Node.js, browsers, and DOM-less environments like Web Workers

Common Use Cases

  • Parsing and normalizing URLs in libraries that must run in both Node.js and browser bundles
  • Extracting query parameters and path segments from request URLs in lightweight routing logic
  • Rewriting or mutating parts of a URL (protocol, host, query) before re-serializing it
  • Parsing URLs inside Web Workers or other environments without access to the DOM <a> trick
  • Acting as the URL-parsing dependency underneath higher-level libraries (historically bundled by Engine.IO/Socket.IO and similar transport libraries)

Under The Hood

Architecture - index.js defines an ordered rules array describing how to progressively slice a URL string (protocol, auth, host, port, path, query, hash), each entry describing which delimiter to scan for and which property to set; the Url function walks this rule set once per parse, mutating an instance object as it consumes characters left-to-right, avoiding both regex backtracking risk and DOM dependencies. Query strings and port defaults are delegated to the small, focused querystringify and requires-port dependencies rather than reimplemented inline. Tech Stack - Plain ES5 JavaScript with only two runtime dependencies (querystringify, requires-port), built for distribution via Browserify into a UMD bundle (dist/url-parse.js) and minified with UglifyJS; tests run under Mocha with c8 coverage and a Sauce Labs cross-browser matrix historically wired into CI. Code Quality - test/test.js and test/fuzzy.js provide direct-assertion and fuzz-style coverage of edge cases (malformed URLs, control characters, Windows drive-letter paths), and the trim helper explicitly avoids a ReDoS-prone regex in favor of a manual character loop, showing deliberate security-conscious implementation choices; however the project has had no commits since early 2023, so it does not track newer URL spec edge cases. API Design - A single default export usable as both new URL(str) and URL(str) (constructor-optional), with a chainable set(key, value) for mutation, keeps the surface minimal; the README itself now recommends the native WHATWG URL API where available, since url-parse predates broad support for it and exists mainly for legacy/embedded-environment compatibility.

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