{"id":17395,"library":"url-parse-as-address","title":"URL Parse As Address","description":"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).","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/isaacs/url-parse-as-address","tags":["javascript","url","parse","addressbar","http"],"install":[{"cmd":"npm install url-parse-as-address","lang":"bash","label":"npm"},{"cmd":"yarn add url-parse-as-address","lang":"bash","label":"yarn"},{"cmd":"pnpm add url-parse-as-address","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import parse from 'url-parse-as-address';\n// OR\nimport { parse } from 'url-parse-as-address';","symbol":"parse","correct":"const parse = require('url-parse-as-address');"},{"note":"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.","wrong":"import { parse } from 'url-parse-as-address/parse'; // Incorrect subpath import","symbol":"parse.parse","correct":"const parse = require('url-parse-as-address');\nconst parsedUrl = parse.parse('foo.com');"},{"note":"`format` is a method on the default export object, not a separate named export. It functions similarly to Node.js's legacy `url.format()`.","wrong":"import { format } from 'url-parse-as-address'; // 'format' is not a named export","symbol":"parse.format","correct":"const parse = require('url-parse-as-address');\nconst formattedUrl = parse.format({ protocol: 'http:', hostname: 'foo.com' });"}],"quickstart":{"code":"const parse = require('url-parse-as-address');\nconst assert = require('assert');\n\nconst urlString = 'foo.com:1234/x?y=z#a=b';\n\n// Basic parsing, query string not parsed into an object\nassert.deepEqual(parse(urlString),\n  { protocol: 'http:',\n    slashes: true,\n    auth: null,\n    host: 'foo.com:1234',\n    port: '1234',\n    hostname: 'foo.com',\n    hash: '#a=b',\n    search: '?y=z',\n    query: 'y=z',\n    pathname: '/x',\n    path: '/x?y=z',\n    href: 'http://foo.com:1234/x?y=z#a=b' });\n\n// Parsing with query string as an object (second argument `true`)\nassert.deepEqual(parse(urlString, true),\n  { protocol: 'http:',\n    slashes: true,\n    auth: null,\n    host: 'foo.com:1234',\n    port: '1234',\n    hostname: 'foo.com',\n    hash: '#a=b',\n    search: '?y=z',\n    query: { y: 'z' },\n    pathname: '/x',\n    path: '/x?y=z',\n    href: 'http://foo.com:1234/x?y=z#a=b' });\n\nconsole.log('All assertions passed!');","lang":"javascript","description":"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."},"warnings":[{"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')`.","message":"This 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.","severity":"deprecated","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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.","cause":"Attempting to use `require()` in an ECMAScript Module (ESM) file.","error":"ReferenceError: require is not defined"},{"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.","cause":"Incorrect ES module `import` syntax used for a CommonJS package that exports a default function.","error":"TypeError: parse is not a function (or similar when trying to import { parse })"}],"ecosystem":"npm","meta_description":null}