is-whatwg-url
Can be parsed or not by whatwg url module.
Why
whatwg-url constructor throw error for normal string. is-whatwg-url
is just validater for whatwg-url constructor.
Usage
const isURL = ;const URL = ;; // false'apple'; // throw Error Invalid URL; // false'/apple'; // throw Error Invalid URL; // false'//apple'; // throw Error Invalid URL; // false'://apple'; // throw Error Invalid URL; // true'a://apple'; // success; // true'a://apple://banana'; // success
How it works
check input string have protocol://
prefix. protocol
should not be empty string.
Caveats
This module does not guarantee that input is URL or not. It just check can be parsed or not.
Alt.
consider using try-catch
instead of this is-whatwg-url
module.
let url;tryurl = 'apple';catch errurl = null;