@cjser/is-absolute-url
v5.0.0-cjser.2
Published
Check if a URL is absolute
Readme
is-absolute-url
Check if a URL is absolute
Install
npm install is-absolute-urlUsage
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});
//=> trueAPI
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
httpOnlytofalsecan pose security risks as it will returntruefor URLs with protocols likejavascript:,vbscript:,data:,ftp:,ws:, etc. Only set this tofalseif you understand the implications and have appropriate safeguards in place.
Related
See is-relative-url for the inverse.
cjser
This package is a CommonJS-compatible build generated by cjser for projects that still need require() support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
Original repository: https://github.com/sindresorhus/is-absolute-url
