Registry / http-networking / url-toolkit

url-toolkit

JSON →
library2.2.5jsnpmunverified

URL Toolkit is a lightweight, dependency-free JavaScript library designed to build absolute URLs from a base URL and a relative URL, specifically adhering to RFC 1808. The current stable version is `2.2.5`. The project maintains a steady release cadence, primarily focusing on bug fixes, performance improvements (like regex optimizations), and security updates (such as ReDoS vulnerability patches), with occasional documentation enhancements. Its key differentiator from the native `URL()` constructor in browsers and Node.js is its strict adherence to RFC 1808, which differs from the WHATWG URL Living Standard used by `URL()`. This difference notably affects how 'special URLs' (like `http:///example.com`) are normalized and parsed, making URL Toolkit suitable for environments or applications that require precise RFC 1808 compliance.

npm install url-toolkit
INSTALL
IMPORT
SIG · URL-TOOLKIT
U
url-toolkit
http-networkingjavascriptv2.2.5
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.

URLToolkit
import * as URLToolkit from 'url-toolkit';
import URLToolkit from 'url-toolkit';
The library exports a namespace object, not a default export. Use `* as` for consistent ESM usage.
buildAbsoluteURL
import { buildAbsoluteURL } from 'url-toolkit';
const { buildAbsoluteURL } = require('url-toolkit');
While CommonJS `require` works, named imports are preferred in modern ESM/TypeScript projects for tree-shaking and clarity.
parseURL
import { parseURL } from 'url-toolkit';
const parseURL = require('url-toolkit').parseURL;
For CommonJS, directly accessing the property is valid, but named ESM imports are generally better practice.

Demonstrates building absolute URLs with and without explicit path normalization, and parsing a URL into its RFC 1808 components.

import { buildAbsoluteURL, parseURL } from 'url-toolkit'; const baseURL = 'https://example.com/path/to/resource.m3u8?query=param#fragment'; const relativeURL = '../new-resource.ts?other=param#anotherFragment'; // Build an absolute URL const absoluteUrl = buildAbsoluteURL(baseURL, relativeURL); console.log('Absolute URL:', absoluteUrl); // Expected: https://example.com/path/new-resource.ts?other=param#anotherFragment // Build an absolute URL with explicit path normalization const absoluteUrlNormalized = buildAbsoluteURL(baseURL, '/root/other.ts', { alwaysNormalize: true }); console.log('Absolute URL (normalized path):', absoluteUrlNormalized); // Expected: https://example.com/root/other.ts // Parse a URL into its components const parsed = parseURL('http://user:pass@host.com:8080/path;params?query=string#hash'); console.log('Parsed URL:', JSON.stringify(parsed, null, 2)); /* Expected: { "scheme": "http:", "netLoc": "//user:pass@host.com:8080", "path": "/path", "params": ";params", "query": "?query=string", "fragment": "#hash" }*/
Debug
Known issues
gotchaURL Toolkit adheres to RFC 1808, which differs from the WHATWG URL Living Standard implemented by the native `URL()` API. This means parsing and resolution logic, especially for 'special URLs' or certain edge cases, will produce different results. For example, `http:///example.com` will be parsed differently.
fix
Thoroughly test URL parsing and resolution if migrating from or using alongside `URL()`. Understand RFC 1808 specifications for expected behavior or use `URL()` if WHATWG standard is preferred.
affects: *
breakingVersions of `url-toolkit` prior to `2.2.4` were vulnerable to Regular Expression Denial of Service (ReDoS) attacks due to inefficient regex patterns in URL parsing logic. Upgrading is crucial for security.
fix
Upgrade to version `2.2.4` or later to incorporate the patched regular expressions: `npm install url-toolkit@latest`.
affects: <2.2.4
gotchaWhen resolving relative URLs containing a colon (e.g., `a:b`), `url-toolkit` treats them as absolute if not prefixed with `./`. To ensure such URLs are treated as relative, explicitly prefix them with `./` (e.g., `./a:b`).
fix
Always use `./` prefix for relative URLs with colons if you intend for them to be resolved against the base URL (e.g., `buildAbsoluteURL(baseURL, './a:b')`).
affects: *
gotchaPath normalization (e.g., resolving `../` or `./`) is not always applied by default unless necessary according to RFC 1808. If you require consistent, full path normalization, you must explicitly set `opts.alwaysNormalize` to `true`.
fix
Pass `{ alwaysNormalize: true }` as the third argument to `buildAbsoluteURL` if consistent path normalization is desired: `buildAbsoluteURL(baseURL, relativeURL, { alwaysNormalize: true })`.
affects: *
gotchaVersion `2.1.5` changed how semicolons (`;`) are handled within URL fragments, allowing them to be correctly included. Older versions might have incorrectly parsed or truncated fragments containing semicolons.
fix
Upgrade to `url-toolkit@2.1.5` or later to ensure correct handling of semicolons within URL fragments.
affects: <2.1.5
Errors
Common errors & fixes
TypeError: URLToolkit.buildAbsoluteURL is not a function
Attempting to destructure `URLToolkit` when using CommonJS `require()` or incorrectly importing in an ESM context.
fix
For CommonJS, use `const URLToolkit = require('url-toolkit'); URLToolkit.buildAbsoluteURL(...)`. For ESM/TypeScript, use `import { buildAbsoluteURL } from 'url-toolkit';` or `import * as URLToolkit from 'url-toolkit'; URLToolkit.buildAbsoluteURL(...)`.
Property 'buildAbsoluteURL' does not exist on type 'typeof import("url-toolkit")' (TypeScript)
Incorrect TypeScript import statement, often trying to use a default import instead of a namespace or named import.
fix
Ensure you are using `import * as URLToolkit from 'url-toolkit';` or `import { buildAbsoluteURL } from 'url-toolkit';` to correctly access the functions.
Unexpected URL resolution result (e.g., `http:///example.com` not normalizing to `http://example.com`)
Misunderstanding the difference between RFC 1808 (implemented by `url-toolkit`) and the WHATWG URL Standard (used by native `URL()`). `url-toolkit` will not perform 'special URL' normalizations like `URL()`.
fix
Review the documentation on 'Differences to JS `URL()`' in the `url-toolkit` README. If WHATWG-compliant behavior is required, consider using the native `URL()` constructor instead.
Upgrade
Version history
2.2.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
url-toolkit — npm install url-toolkit · libregistry