{"id":17275,"library":"is-valid-http-url","title":"HTTP URL String Validator","description":"This package provides a focused utility function to determine if a given string adheres to the structural requirements of an HTTP or HTTPS URL. Currently at version 1.0.3, it is a stable, low-cadence library, primarily maintained for compatibility and reliability rather than frequent feature additions. Its core validation logic is built upon a robust regular expression initially developed by Diego Perini, which is well-regarded for its comprehensive coverage of various URL components. Unlike larger, more feature-rich URL parsing libraries, `is-valid-http-url` offers a lightweight and direct API specifically for string format validation, making it ideal for scenarios where only a quick check for valid HTTP/HTTPS URL syntax is needed without additional overhead.","status":"maintenance","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/neosiae/is-valid-http-url","tags":["javascript","http","url","uri","string","check","validate","validation"],"install":[{"cmd":"npm install is-valid-http-url","lang":"bash","label":"npm"},{"cmd":"yarn add is-valid-http-url","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-valid-http-url","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library exports a single function as its default. Use default import for ESM.","wrong":"import { isUrl } from 'is-valid-http-url';","symbol":"isUrl","correct":"import isUrl from 'is-valid-http-url';"},{"note":"For CommonJS environments, the function is directly exported via `module.exports`.","symbol":"isUrl","correct":"const isUrl = require('is-valid-http-url');"}],"quickstart":{"code":"import isUrl from 'is-valid-http-url';\n\n// Test cases for valid HTTP/HTTPS URLs\nconsole.log('Valid URLs:');\nconsole.log(`http://example.com: ${isUrl('http://example.com')}`);\nconsole.log(`https://www.example.com/foo/?bar=baz&inga=42&quux: ${isUrl('https://www.example.com/foo/?bar=baz&inga=42&quux')}`);\nconsole.log(`http://localhost:3000: ${isUrl('http://localhost:3000')}`);\nconsole.log(`https://user:pass@host.com/path?query#hash: ${isUrl('https://user:pass@host.com/path?query#hash')}`);\n\nconsole.log('\\nInvalid URLs:');\n// Test cases for invalid URLs\nconsole.log(`example.com (missing scheme): ${isUrl('example.com')}`);\nconsole.log(`http://foo.bar?q=Spaces should be encoded: ${isUrl('http://foo.bar?q=Spaces should be encoded')}`);\nconsole.log(`ftp://example.com (non-http scheme): ${isUrl('ftp://example.com')}`);\nconsole.log(`invalid-url: ${isUrl('invalid-url')}`);\nconsole.log(`\nNote: This validator checks syntax, not if the URL actually exists or is reachable.`);","lang":"javascript","description":"This quickstart demonstrates how to import and use the `isUrl` function to validate various HTTP and HTTPS URL strings, showcasing both valid and invalid examples."},"warnings":[{"fix":"If you require validation beyond format (e.g., checking if a URL is alive), you will need to integrate additional network request logic (e.g., using `fetch` or `axios`).","message":"This library only validates the *format* of an HTTP/HTTPS URL string. It does not perform DNS lookups, check for server availability, or verify the existence of the resource at the given URL.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For validating non-HTTP/HTTPS URLs, use a more general URL parsing library or a validator specific to that protocol.","message":"The validator is specifically designed for HTTP and HTTPS protocols. It will return `false` for URLs using other schemes like `ftp://`, `mailto:`, `file://`, etc., even if their format is otherwise correct for their respective schemes.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For critical applications with highly varied URL inputs, consider combining this with broader URL parsing libraries like Node.js's built-in `URL` class or `url-parse` for deeper structural analysis if needed.","message":"The validation logic is based on a regular expression. While robust, extremely rare or highly unusual URL formats might not be perfectly covered. Ensure URLs conform to standard RFCs for best results.","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":"Change the import statement to `import isUrl from 'is-valid-http-url';` for ESM environments.","cause":"Attempting to use a named import (`import { isUrl } from '...'`) for a package that provides a default export in an ESM context.","error":"TypeError: (0 , is_valid_http_url_1.default) is not a function"},{"fix":"Ensure you are using `const isUrl = require('is-valid-http-url');` in CommonJS, or `import isUrl from 'is-valid-http-url';` in ESM, as the package provides a default function export.","cause":"Occurs when `require()` is used on a module that primarily expects ESM default imports, or if the imported name does not match the exported symbol.","error":"TypeError: isUrl is not a function"}],"ecosystem":"npm","meta_description":null}