The `url-to-options` package is a focused utility designed to convert a WHATWG `URL` object into a plain JavaScript options object compatible with Node.js's native `http.request` and `https.request` methods. It abstracts the process of extracting host, port, protocol, auth, and path information from a standard URL representation. The current stable version is 2.0.0. Given its specific utility nature, the package is expected to have an infrequent release cadence, primarily for maintenance, bug fixes, or compatibility with newer Node.js versions or WHATWG URL specification changes. Its primary differentiator is its directness in bridging the WHATWG URL standard with Node's built-in HTTP client APIs, providing a clean way to construct request options without manual parsing.
npm install url-to-optionsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to convert a WHATWG `URL` instance into an options object suitable for Node.js `http.request` or `https.request`, logging the resulting object.
For pure ESM Node.js environments, consider using a bundler like Webpack or Rollup, or ensure your Node.js version is recent enough (e.g., 12.17.0+ or 13.2.0+) for improved CJS-ESM interop. If issues persist, dynamic `import()` might be an option: `const urlToOptions = await import('url-to-options');`.Always construct a `URL` instance before passing it to `urlToOptions`. Example: `const url = new URL('http://example.com'); urlToOptions(url);`.For most users, no fix is needed as it's forward compatible. If an issue arises specific to a very new Node.js version, consider reporting it to the maintainer or evaluating if an alternative parsing method is more suitable for your environment.
Ensure you create a `URL` object using `new URL('your-url-string')` before passing it to `url-to-options`. For example: `const myUrl = new URL('https://example.com'); const opts = urlToOptions(myUrl);`In an ESM project, use the ESM import syntax: `import urlToOptions from 'url-to-options';`. If this still causes issues, check your `package.json` for `"type": "module"` and ensure Node.js is handling CJS interop correctly for your version. You might also need a bundler.
No dependency data recorded yet.