is-absolute-url

Check if a URL is absolute

MIT 11 个版本
安装
npm install is-absolute-url
yarn add is-absolute-url
pnpm add is-absolute-url
bun add is-absolute-url
README

is-absolute-url

Check if a URL is absolute

Install

npm install is-absolute-url

Usage

import isAbsoluteUrl from 'is-absolute-url';

isAbsoluteUrl('https://sindresorhus.com/foo/bar');
//=> true

isAbsoluteUrl('//sindresorhus.com');
//=> false

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

isAbsoluteUrl('javascript:alert(1)');
//=> false

isAbsoluteUrl('javascript:alert(1)', {httpOnly: false});
//=> true

API

isAbsoluteUrl(url, options?)

url

Type: string

The URL to check.

options

Type: object

httpOnly

Type: boolean
Default: true

Only allow HTTP(S) protocols.

When set to false, any valid absolute URL will be accepted, including potentially unsafe protocols like javascript:, ftp:, ws:, etc.

Warning: Setting httpOnly to false can pose security risks as it will return true for URLs with protocols like javascript:, vbscript:, data:, ftp:, ws:, etc. Only set this to false if you understand the implications and have appropriate safeguards in place.

See is-relative-url for the inverse.

版本列表
5.0.0 2025-09-13
4.0.1 2021-08-11
4.0.0 2021-08-10
3.0.3 2019-09-29
3.0.2 2019-09-13
3.0.1 2019-08-18
3.0.0 2019-04-06
2.1.0 2016-12-11
2.0.0 2015-07-03
1.0.0 2014-08-13
0.1.0 2014-06-29