is-url-http

2.3.13 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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

view raw JSON →