Check if a URL is absolute
By default, it checks if the URL uses the http
or https
protocol.
$ npm install is-absolute-url
const isAbsoluteUrl = require('is-absolute-url');
isAbsoluteUrl('https://sindresorhus.com/foo/bar');
//=> true
isAbsoluteUrl('http://sindresorhus.com/foo/bar');
//=> true
isAbsoluteUrl('ftp://sindresorhus.com/foo/bar');
//=> false
isAbsoluteUrl('ftp://sindresorhus.com/foo/bar', {httpOnly: false});
//=> true
isAbsoluteUrl('//sindresorhus.com');
//=> false
isAbsoluteUrl('foo/bar');
//=> false
By default only http
and https
links are validated. If you wish to check absolute URLs of protocols other than http
(for example, ftp:
, mailto:
), use isAbsoluteUrl(mayBeURL, { httpOnly: false })
.
Type: string
The URL to be checked.
Type: object
Type: boolean
Default: true
Set to false
if the url does not use http
/https
protocol.
See is-relative-url for the inverse.
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.