URL Utilities

ngx-lift provides several utility functions for working with URLs: isIP and isFQDN for checking hostname types, isURL for validating URLs, and isHttps for checking HTTPS protocol. These utilities are useful for URL validation, security checks, and conditional logic based on URL properties.

Examples

Example 1: Check Hostname Type (isIP & isFQDN)

Check if a URL hostname is an IP address or a fully qualified domain name (FQDN):

import {isFQDN, isIP} from 'ngx-lift';

console.log(isFQDN('www.example.com')); // true
console.log(isFQDN('192.168.0.1')); // false

console.log(isIP('www.example.com')); // false
console.log(isIP('192.168.0.1')); // true
import {isFQDN} from 'ngx-lift';

try {
  const hostname = new URL('your-url').hostname;

  if (isFQDN(hostname)) {
    // the rest of your logic
  }
} catch (error) {
  // your-url is invalid
  console.error(error);
}

Example 2: Validate URLs (isURL & isHttps)

isURL is used to check if a URL is valid. isHttps is used to check if the URL starts with https.

import {isHttps, isURL} from 'ngx-lift';

console.log(isURL('http://www.example.com')); // true
console.log(isURL('invalid-url')); // false
console.log(isHttps('https://192.168.0.1')); // true
console.log(isHttps('http://www.example.com')); // false

API Reference

isIP

Checks if a hostname is an IP address.

Signature

isIP(hostname: string): boolean

isFQDN

Checks if a hostname is a fully qualified domain name (FQDN).

Signature

isFQDN(hostname: string): boolean

isURL

Checks if a string is a valid URL.

Signature

isURL(url: string): boolean

isHttps

Checks if a URL string uses the HTTPS protocol.

Signature

isHttps(url: string): boolean