is-absolute-url
Check if a URL is absolute
Last updated a year ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install is-absolute-url 
SYNC missed versions from official npm registry.

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.

Related

See is-relative-url for the inverse.

Current Tags

  • 5.0.0                                ...           latest (a year ago)

11 Versions

  • 5.0.0                                ...           a year ago
  • 4.0.1                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 3.0.3                                ...           7 years ago
  • 3.0.2                                ...           7 years ago
  • 3.0.1                                ...           7 years ago
  • 3.0.0                                ...           8 years ago
  • 2.1.0                                ...           10 years ago
  • 2.0.0                                ...           11 years ago
  • 1.0.0                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 38
Today 0
This Week 0
This Month 14
Last Day 0
Last Week 1
Last Month 11
Dependencies (0)
None
Dev Dependencies (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE