What is is-relative-url?
The is-relative-url npm package is a simple utility that checks if a given URL is a relative URL. It is useful for validating and processing URLs in web development.
What are is-relative-url's main functionalities?
Check if a URL is relative
This feature allows you to check if a given URL is relative. A relative URL does not include the domain name and is relative to the current page's URL.
const isRelativeUrl = require('is-relative-url');
console.log(isRelativeUrl('/path/to/resource')); // true
console.log(isRelativeUrl('http://example.com')); // false
Other packages similar to is-relative-url
is-absolute-url
The is-absolute-url package checks if a given URL is an absolute URL. It complements is-relative-url by providing the opposite functionality, allowing developers to validate absolute URLs.
url-parse
The url-parse package is a more comprehensive URL parsing library that can handle both relative and absolute URLs. It provides more advanced features such as extracting components of the URL, making it more versatile compared to is-relative-url.
valid-url
The valid-url package provides functions to validate URLs, including checking if they are valid, absolute, or relative. It offers a broader range of validation options compared to is-relative-url.
is-relative-url
Check if a URL is relative
Install
npm install is-relative-url
Usage
import isRelativeUrl from 'is-relative-url';
isRelativeUrl('foo/bar');
isRelativeUrl('https://sindresorhus.com/foo/bar');
isRelativeUrl('//sindresorhus.com');
Related
See is-absolute-url for the inverse.