Registry / http-networking / is-url-http

is-url-http

JSON →
library2.3.13jsnpmunverified

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.

npm install is-url-http
INSTALL
IMPORT
SIG · IS-URL-HTTP
I
is-url-http
http-networkingjavascriptv2.3.13
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.

isUrlHttp
import isUrlHttp from 'is-url-http';
import { isUrlHttp } from 'is-url-http';
The library's main function is exported as a CommonJS `module.exports =` which translates to a default import in ESM. Avoid named imports.
isUrlHttp (CommonJS)
const isUrlHttp = require('is-url-http');
const { isUrlHttp } = require('is-url-http');
Standard CommonJS import for Node.js environments. The function is the direct module export, not a named property.
isUrlHttp (lightweight bundle)
import isUrlHttpLight from 'is-url-http/lightweight';
import { isUrlHttpLight } from 'is-url-http/lightweight';
Imports the smaller bundle suitable for browser environments. Similar to the main export, it is a default export.
Type of isUrlHttp function
import type IsUrlHttp from 'is-url-http';
To get the TypeScript type for the default exported function, use a default type import or `typeof import('is-url-http')`.

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.

import isUrlHttp from 'is-url-http'; import isUrlHttpLight from 'is-url-http/lightweight'; console.log('--- Standard Version ---'); console.log('Valid HTTPS:', isUrlHttp('https://kikobeats.com')); // Expected: true console.log('Valid HTTP:', isUrlHttp('http://localhost:3000')); // Expected: true console.log('Invalid FTP scheme:', isUrlHttp('ftp://example.com')); // Expected: false console.log('Invalid Mailto scheme:', isUrlHttp('mailto:test@example.com')); // Expected: false console.log('Malformed URL string:', isUrlHttp('invalid-url-string')); // Expected: false console.log('\n--- Lightweight Version ---'); console.log('Valid HTTPS (light):', isUrlHttpLight('https://kikobeats.com')); // Expected: true console.log('Valid HTTP (light):', isUrlHttpLight('http://localhost:3000')); // Expected: true console.log('Invalid WS scheme (light):', isUrlHttpLight('ws://example.com')); // Expected: false console.log('URL with trailing space (light):', isUrlHttpLight(' https://trailing-space.com ')); // Expected: true
Debug
Known issues
gotchaThis 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.
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.
affects: >=2.0.0
gotchaThe `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.
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.
affects: >=2.3.0
Errors
Common errors & fixes
TypeError: (0 , is_url_http_1.default) is not a function
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.
fix
Use a default import instead: `import isUrlHttp from 'is-url-http';`
TypeError: isUrlHttp is not a function
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`.
fix
Assign the `require` call directly to the function variable: `const isUrlHttp = require('is-url-http');`
Error: Cannot find module 'is-url-http/lightweight'
Incorrect module path specified for the lightweight bundle, or the dependency was not installed correctly.
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.
Upgrade
Version history
2.3.13latest on npm
Audit
Dependencies
url-httprequiredCore dependency for robust WHATWG URL parsing and validation logic.
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
is-url-http — npm install is-url-http · libregistry