url-parse
Small, dependency-light URL parser that works identically in Node.js and the browser.
Repository Health
Technical Analysis
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
Urlconstructor/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
querystringifymodule - Protocol-aware default port handling through the
requires-portmodule - 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.
Used by 4 apps in this directory
APITable
Low Code Platforms · Databases
API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.
Joplin
Note Taking
The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.
matomo
Analytics
Open-source, privacy-first web and app analytics that puts you in complete control of your data.
swagger-ui
Developer Tools
Transform OpenAPI specifications into interactive, browser-based API documentation that developers and consumers can explore and test live.