url-parse is a URL parsing library designed for both Node.js and browser environments, emphasizing a small footprint. Originally created in 2014, it addressed the lack of a standardized WHATWG URL API across platforms. The package is currently at version 1.5.10 and receives infrequent updates, focusing on stability. It provides two distinct API interfaces: one that emulates the Node.js `url` module and another that behaves similarly to the modern browser `URL` interface. Its core differentiator is a pure string parsing approach, introduced in version 1.0.0, which ensures broad compatibility, particularly in environments without DOM access like Web Workers. It also bundles and exposes the `querystringify` module for robust query string handling. Critically, the project maintainers strongly recommend using the native `URL` interface for new development due to its superior security and accuracy, positioning `url-parse` primarily as a solution for legacy compatibility.
npm install url-parseVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic URL parsing, enabling query string parsing, resolving relative URLs with a base, and direct usage of the bundled `querystringify` module.
For new projects, use `new URL()` or `URL.parse()` (if available) and `URLSearchParams` for query string manipulation. Review existing code for potential security implications if `url-parse` handles untrusted input.
When creating a `URLParse` instance, pass `true` as the second argument: `new URLParse('your-url', true)` to enable default query string parsing. Alternatively, use `urlParseInstance.set('query', { /* new object */ }, true);` to trigger re-parsing.Thoroughly test parsing behavior for critical URL patterns when migrating to or from version 1.0.0, especially if relying on specific outcomes for unusual or malformed URLs.
If migrating from pre-0.1 versions, ensure your environment supports the new parsing mechanism. For Web Worker compatibility, version 0.1 was an improvement, but later versions refined parsing further.
Pass `true` as the second argument to the `URLParse` constructor/function: `const url = new URLParse('http://example.com?a=1', true);` to enable default querystring parsing.For CommonJS: `const URLParse = require('url-parse');`. For ES Modules, which might require bundler support for this CJS-first package: `import URLParse from 'url-parse';`. Avoid named imports like `import { URLParse } from 'url-parse';` for the main export.Provide a base URL string or `URLParse` object as the second argument when parsing relative URLs: `const resolvedUrl = new URLParse('/images/logo.png', 'http://example.com/');`No dependency data recorded yet.