url-parser-lite is a minimal URL parsing utility designed for all JavaScript environments, including browsers and Node.js. Currently at version 0.1.0, its primary differentiator is its extremely small footprint, weighing in at less than 1 kilobyte (specifically, 360 bytes). It provides basic parsing capabilities for common URL components like protocol, authentication, host, path, hash, and query parameters. The library prioritizes size and simplicity over comprehensive RFC compliance or advanced features found in native `URL` objects or larger parsing libraries. Given its early version, the release cadence is not yet established, but it serves as a straightforward alternative for environments where bundle size is critical and full URL specification adherence is not required. Its implementation is based on a well-regarded Stack Overflow answer, aiming for robust parsing of common URL patterns without external dependencies.
npm install url-parser-liteVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic URL parsing, handling authentication and query parameters, and showing how to access the individual parsed components returned by the lightweight `url-parser-lite` function.
If distinct hostname and port are needed, manually parse the `host` string, e.g., `const [hostname, port] = parsedUrl.host.split(':');`For object representation of query parameters, manually parse the `query` string or use a separate utility like `new URLSearchParams(parsedUrl.query)`.
Ensure input URLs are generally well-formed. For robust validation or complex URL scenarios, consider using the native `URL` API or a more feature-rich library.
Pin to exact versions (e.g., `0.1.0`) if stability is critical, and thoroughly review changelogs when upgrading to any new `0.x.y` release.
Call `URL` directly as a function: `const parsed = URL('https://example.com');`For ES Modules, ensure `import URL from 'url-parser-lite';` is at the top of the file. For CommonJS, if supported, use `const URL = require('url-parser-lite');` (check package compatibility).Extract the port from the `host` string manually: `const hostParts = parsed.host.split(':'); const port = hostParts.length > 1 ? hostParts[1] : null;`No dependency data recorded yet.