Registry / serialization / url-parse-as-address

url-parse-as-address

JSON →
library1.0.0jsnpmunverified

url-parse-as-address is a JavaScript utility for parsing URL strings, specifically designed to assume the `http` protocol if no scheme or leading `//` is explicitly provided. This behavior mimics how web browsers handle incomplete URL inputs, making it suitable for scenarios where user-entered addresses might lack full protocol specification (e.g., 'foo.com' instead of 'http://foo.com'). Published as version 1.0.0 over a decade ago, this package primarily functions as a CommonJS module. It provides a parsed object structure similar to Node.js's legacy `url.parse()` method, including properties like `protocol`, `host`, `pathname`, and `query`. Due to its age and lack of updates, newer projects are generally advised to use the WHATWG `URL` API (built into Node.js and modern browsers) or more actively maintained alternatives that offer better security, features, and ESM support, especially given its limited ecosystem adoption (17 dependents).

npm install url-parse-as-address
INSTALL
IMPORT
SIG · URL-PARSE-AS-ADDRE
U
url-parse-as-address
serializationjavascriptv1.0.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.

parse
const parse = require('url-parse-as-address');
import parse from 'url-parse-as-address'; // OR import { parse } from 'url-parse-as-address';
This package is a CommonJS module and must be imported using `require()`. Attempting to use ES module `import` syntax will result in a runtime error unless transpiled.
parse.parse
const parse = require('url-parse-as-address'); const parsedUrl = parse.parse('foo.com');
import { parse } from 'url-parse-as-address/parse'; // Incorrect subpath import
The main exported function is also available as a property `parse.parse` for symmetry with Node.js's built-in `url` module. It's not a separate named export.
parse.format
const parse = require('url-parse-as-address'); const formattedUrl = parse.format({ protocol: 'http:', hostname: 'foo.com' });
import { format } from 'url-parse-as-address'; // 'format' is not a named export
`format` is a method on the default export object, not a separate named export. It functions similarly to Node.js's legacy `url.format()`.

Demonstrates basic URL parsing with `url-parse-as-address`, showing how it defaults to `http:` protocol and how to optionally parse query strings into an object.

const parse = require('url-parse-as-address'); const assert = require('assert'); const urlString = 'foo.com:1234/x?y=z#a=b'; // Basic parsing, query string not parsed into an object assert.deepEqual(parse(urlString), { protocol: 'http:', slashes: true, auth: null, host: 'foo.com:1234', port: '1234', hostname: 'foo.com', hash: '#a=b', search: '?y=z', query: 'y=z', pathname: '/x', path: '/x?y=z', href: 'http://foo.com:1234/x?y=z#a=b' }); // Parsing with query string as an object (second argument `true`) assert.deepEqual(parse(urlString, true), { protocol: 'http:', slashes: true, auth: null, host: 'foo.com:1234', port: '1234', hostname: 'foo.com', hash: '#a=b', search: '?y=z', query: { y: 'z' }, pathname: '/x', path: '/x?y=z', href: 'http://foo.com:1234/x?y=z#a=b' }); console.log('All assertions passed!');
Debug
Known issues
deprecatedThis package is very old (last updated over 11 years ago) and is considered abandoned. It has not received updates for security vulnerabilities, bug fixes, or compatibility with modern JavaScript environments. Its parsing logic may not fully align with current URL specifications or edge cases handled by modern URL parsers.
fix
Migrate to Node.js's built-in `URL` class (WHATWG URL API) or a well-maintained third-party library like `url-parse` or `parseuri` for robust and secure URL handling. Example: `new URL('http://foo.com')` or `new URL('foo.com', 'http://base.com')`.
affects: >=1.0.0
gotchaThe package is a CommonJS module and does not support ES module `import` syntax directly. Attempting to `import` it in an ESM environment will cause a runtime error.
fix
Use `const parse = require('url-parse-as-address');` for CommonJS environments. In an ESM context, you may need to use `createRequire` from `node:module` or dynamic `import()` if you absolutely must use this package, but migration is strongly recommended.
affects: >=1.0.0
gotchaThe primary differentiation of this library is its assumption of 'http:' protocol for URLs without a scheme (e.g., 'foo.com'). While this is useful for browser-like input, it deviates from the strict parsing of the WHATWG `URL` API, which requires a valid base URL for relative or protocol-less inputs. This can lead to different parsing results compared to modern standards.
fix
Understand this specific parsing behavior and ensure it aligns with your application's requirements. If strict adherence to WHATWG URL parsing is needed, use the native `URL` class or alternatives that implement it.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ECMAScript Module (ESM) file.
fix
This package is CommonJS-only. If your project is ESM, either convert the file to CommonJS (`.cjs` or `"type": "commonjs"` in `package.json`) or use `import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);` to create a `require` function in ESM. It's better to migrate away from this package.
TypeError: parse is not a function (or similar when trying to import { parse })
Incorrect ES module `import` syntax used for a CommonJS package that exports a default function.
fix
Use `const parse = require('url-parse-as-address');` as the package exports its main function as the `module.exports` object. It does not have named exports for `parse` or `format` in the ESM sense.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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