Registry / serialization / url-parser-lite

url-parser-lite

JSON →
library0.1.0jsnpmunverified

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-lite
INSTALL
IMPORT
SIG · URL-PARSER-LITE
U
url-parser-lite
serializationjavascriptv0.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

URL
import URL from 'url-parser-lite';
url-parser-lite provides a default export, which is a function. Call it directly (e.g., `URL('...')`) instead of using `new URL(...)`.
URL
import URL from 'url-parser-lite';
import { URL } from 'url-parser-lite';
The library uses a default export, so destructuring with curly braces will result in an undefined `URL` symbol.
URL
import URL from 'url-parser-lite';
const URL = require('url-parser-lite');
While some older bundles might support CommonJS `require`, the primary and documented usage is via ES Modules `import`. Relying on `require` may lead to issues in pure ESM environments or different bundling setups.

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.

import URL from 'url-parser-lite'; // Example 1: Basic URL parsing const simpleUrl = URL('https://example.com/path/to/page?key=value#section'); console.log('Simple URL:', simpleUrl); // Expected output: { protocol: 'https', auth: '', host: 'example.com', path: '/path/to/page', hash: 'section', query: 'key=value' } // Example 2: URL with authentication (port will be part of host) const authUrl = URL('http://user:pass@sub.domain.com:8080/dir/index.html?param1=foo&param2=bar#fragment'); console.log('Auth URL:', authUrl); // Expected output includes: host: 'sub.domain.com:8080' // Example 3: Parsing a complex URL and accessing components const parsedURL = URL('https://username:pa$$w0rd@github.com/metagrover/some/repo?repos=21&limit=10#readme'); console.log('Protocol:', parsedURL.protocol); // "https" console.log('Host:', parsedURL.host); // "github.com" console.log('Query:', parsedURL.query); // "repos=21&limit=10" console.log('Hash:', parsedURL.hash); // "readme" console.log('Auth:', parsedURL.auth); // "username:pa$$w0rd"
Debug
Known issues
gotchaThe `host` property returned by `url-parser-lite` includes both the hostname and the port number (e.g., `example.com:8080`) as a single string, unlike the native `URL` API which separates them into `hostname` and `port`.
fix
If distinct hostname and port are needed, manually parse the `host` string, e.g., `const [hostname, port] = parsedUrl.host.split(':');`
affects: >=0.1.0
gotcha`url-parser-lite` does not parse the `query` string into an object (e.g., `URLSearchParams`). The `query` property returns the raw query string (e.g., "key=value&key2=value2").
fix
For object representation of query parameters, manually parse the `query` string or use a separate utility like `new URLSearchParams(parsedUrl.query)`.
affects: >=0.1.0
gotchaAs a lightweight parser, `url-parser-lite` provides limited validation and may produce unexpected or incomplete results for highly malformed or non-standard URLs (e.g., relative paths without a base URL, incomplete protocols). It prioritizes size over comprehensive RFC compliance.
fix
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.
affects: >=0.1.0
breakingGiven its `0.1.0` version, the API surface and internal parsing logic are subject to change in future minor (`0.x.y`) or major versions without strict adherence to semantic versioning until a `1.0.0` release. Breaking changes may occur in non-major version bumps.
fix
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.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: URL is not a function
Attempting to invoke the `URL` parser function with the `new` keyword (e.g., `new URL(...)`), treating it as a class or native constructor.
fix
Call `URL` directly as a function: `const parsed = URL('https://example.com');`
ReferenceError: URL is not defined
The `URL` function was not correctly imported (e.g., missing `import URL from 'url-parser-lite';`) or attempting to use it in a CommonJS environment with an ESM import syntax, or vice versa if the CommonJS export isn't configured.
fix
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).
Output object lacks expected `port` property (e.g., `parsedUrl.port` is undefined).
`url-parser-lite` merges the hostname and port into a single `host` string property (e.g., `example.com:8080`), rather than providing a separate `port` property.
fix
Extract the port from the `host` string manually: `const hostParts = parsed.host.split(':'); const port = hostParts.length > 1 ? hostParts[1] : null;`
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
url-parser-lite — npm install url-parser-lite · libregistry