CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-is-absolute-url

Check if a URL is absolute

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

is-absolute-url

Check if a URL is absolute. A lightweight utility function that determines whether a given URL string contains a protocol scheme, following RFC 3986 standards with special handling for Windows file path edge cases.

Package Information

  • Package Name: is-absolute-url
  • Package Type: npm
  • Language: JavaScript (ES modules)
  • Installation: npm install is-absolute-url

Core Imports

import isAbsoluteUrl from 'is-absolute-url';

This package is ES module only and does not support CommonJS require().

Basic Usage

import isAbsoluteUrl from 'is-absolute-url';

// Absolute URLs (contain protocol scheme)
isAbsoluteUrl('https://sindresorhus.com/foo/bar');
//=> true

isAbsoluteUrl('http://example.com');
//=> true

isAbsoluteUrl('file://path/to/file');
//=> true

isAbsoluteUrl('mailto:someone@example.com');
//=> true

isAbsoluteUrl('data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D');
//=> true

// Case insensitive scheme matching
isAbsoluteUrl('httpS://example.com');
//=> true

// Relative URLs (no protocol scheme)
isAbsoluteUrl('//sindresorhus.com');
//=> false

isAbsoluteUrl('/foo/bar');
//=> false

isAbsoluteUrl('foo/bar');
//=> false

// Windows paths are handled as non-absolute
isAbsoluteUrl('c:\\Windows\\System32');
//=> false

// Invalid scheme characters
isAbsoluteUrl('ht,tp://example.com');
//=> false

Capabilities

URL Validation

Determines if a URL string is absolute by checking for a valid protocol scheme.

/**
 * Check if a URL is absolute
 * @param {string} url - The URL string to check
 * @returns {boolean} true if the URL is absolute, false otherwise
 * @throws {TypeError} if url parameter is not a string
 */
export default function isAbsoluteUrl(url) {}

Parameters:

  • url (string): The URL string to validate

Returns:

  • boolean: true if the URL contains a valid protocol scheme, false otherwise

Throws:

  • TypeError: If the url parameter is not a string

Implementation Details:

  • Uses RFC 3986 compliant regex pattern for scheme validation
  • Scheme must start with a letter followed by letters, digits, +, -, or .
  • Explicitly rejects Windows file paths (e.g., c:\) to avoid false positives
  • Case-insensitive scheme matching

Supported URL Schemes: All RFC 3986 compliant schemes are supported, including but not limited to:

  • http:// and https://
  • file://
  • mailto:
  • data:
  • ftp://
  • ldap://
  • Custom schemes following the RFC pattern

Edge Cases:

  • Protocol-relative URLs (//example.com) return false
  • Windows file paths (c:\, C:\Dev\) return false
  • Invalid scheme characters (ht,tp://) return false
  • Empty strings return false

Error Handling

The function validates input types and throws a descriptive error for non-string inputs:

try {
  isAbsoluteUrl(123);
} catch (error) {
  console.log(error.message);
  // "Expected a `string`, got `number`"
}

docs

index.md

tile.json