{"id":16401,"library":"is-url-http","title":"is-url-http","description":"is-url-http is a focused utility library for JavaScript and TypeScript environments that efficiently determines if a given string represents a valid HTTP or HTTPS URL. It primarily checks the scheme (http or https) and basic URL structure based on WHATWG URL Standard conventions. The current stable version is 2.3.13, and the library exhibits an active maintenance schedule with frequent patch and minor updates, typically every few weeks, addressing bug fixes and minor enhancements. Its key differentiators include its singular focus on HTTP/HTTPS URL validation, ensuring a small footprint and predictable behavior without delving into broader URL parsing concerns. A notable feature is the provision of a separate 'lightweight' bundle, specifically optimized for browser environments, which aims to minimize bundle size while retaining core validation functionality. This makes it an ideal choice for client-side applications where every byte counts, differentiating it from more comprehensive URL manipulation libraries.","status":"active","version":"2.3.13","language":"javascript","source_language":"en","source_url":"https://github.com/Kikobeats/is-url-http","tags":["javascript","boolean","check","http","https","is","url","whatwg","typescript"],"install":[{"cmd":"npm install is-url-http","lang":"bash","label":"npm"},{"cmd":"yarn add is-url-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-url-http","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for robust WHATWG URL parsing and validation logic.","package":"url-http","optional":false}],"imports":[{"note":"The library's main function is exported as a CommonJS `module.exports =` which translates to a default import in ESM. Avoid named imports.","wrong":"import { isUrlHttp } from 'is-url-http';","symbol":"isUrlHttp","correct":"import isUrlHttp from 'is-url-http';"},{"note":"Standard CommonJS import for Node.js environments. The function is the direct module export, not a named property.","wrong":"const { isUrlHttp } = require('is-url-http');","symbol":"isUrlHttp (CommonJS)","correct":"const isUrlHttp = require('is-url-http');"},{"note":"Imports the smaller bundle suitable for browser environments. Similar to the main export, it is a default export.","wrong":"import { isUrlHttpLight } from 'is-url-http/lightweight';","symbol":"isUrlHttp (lightweight bundle)","correct":"import isUrlHttpLight from 'is-url-http/lightweight';"},{"note":"To get the TypeScript type for the default exported function, use a default type import or `typeof import('is-url-http')`.","symbol":"Type of isUrlHttp function","correct":"import type IsUrlHttp from 'is-url-http';"}],"quickstart":{"code":"import isUrlHttp from 'is-url-http';\nimport isUrlHttpLight from 'is-url-http/lightweight';\n\nconsole.log('--- Standard Version ---');\nconsole.log('Valid HTTPS:', isUrlHttp('https://kikobeats.com')); // Expected: true\nconsole.log('Valid HTTP:', isUrlHttp('http://localhost:3000'));   // Expected: true\nconsole.log('Invalid FTP scheme:', isUrlHttp('ftp://example.com'));       // Expected: false\nconsole.log('Invalid Mailto scheme:', isUrlHttp('mailto:test@example.com')); // Expected: false\nconsole.log('Malformed URL string:', isUrlHttp('invalid-url-string'));                   // Expected: false\n\nconsole.log('\\n--- Lightweight Version ---');\nconsole.log('Valid HTTPS (light):', isUrlHttpLight('https://kikobeats.com')); // Expected: true\nconsole.log('Valid HTTP (light):', isUrlHttpLight('http://localhost:3000')); // Expected: true\nconsole.log('Invalid WS scheme (light):', isUrlHttpLight('ws://example.com'));       // Expected: false\nconsole.log('URL with trailing space (light):', isUrlHttpLight('  https://trailing-space.com  ')); // Expected: true\n","lang":"typescript","description":"Demonstrates how to import and use both the standard and lightweight versions of `is-url-http` to validate different URL strings, highlighting their simple boolean return."},"warnings":[{"fix":"Understand that `is-url-http` is for scheme validation only; for broader URL validation or network reachability checks, consider a more comprehensive URL parsing library or a dedicated network library.","message":"This library exclusively validates against `http://` and `https://` schemes, based on WHATWG URL Standard conventions. URLs with other protocols (e.g., `ftp://`, `mailto://`, `ws://`) will always return `false`, even if they are syntactically valid for their respective schemes. It does not perform network requests or check for URL reachability.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Perform comprehensive testing against your specific URL patterns when using the lightweight bundle. For critical or complex URL validation scenarios where absolute consistency with WHATWG standards is paramount, consider using the full `is-url-http` package.","message":"The `is-url-http/lightweight` bundle is optimized for size, primarily for browser environments. While generally functionally equivalent for typical HTTP/HTTPS URLs, it might use a simplified underlying URL parsing mechanism derived from its `url-http` dependency. This could lead to subtle differences in edge-case handling (e.g., highly malformed URLs, specific internationalized domain names) compared to the full version.","severity":"gotcha","affected_versions":">=2.3.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Use a default import instead: `import isUrlHttp from 'is-url-http';`","cause":"Attempting to use `isUrlHttp` as a named import (e.g., `import { isUrlHttp } from 'is-url-http';`) in an ESM context, when the library exports its main function as a default export.","error":"TypeError: (0 , is_url_http_1.default) is not a function"},{"fix":"Assign the `require` call directly to the function variable: `const isUrlHttp = require('is-url-http');`","cause":"Attempting to destructure `isUrlHttp` from a `require` statement (e.g., `const { isUrlHttp } = require('is-url-http');`) in a CommonJS environment, when the module exports the function directly as `module.exports`.","error":"TypeError: isUrlHttp is not a function"},{"fix":"Ensure the import path is exactly `is-url-http/lightweight`. Verify `node_modules` structure and run `npm install` or `yarn install` to ensure all dependencies are correctly placed. If using bundlers, check alias configurations.","cause":"Incorrect module path specified for the lightweight bundle, or the dependency was not installed correctly.","error":"Error: Cannot find module 'is-url-http/lightweight'"}],"ecosystem":"npm"}