index.js 413 B

12345678910111213141516
  1. 'use strict';
  2. module.exports = url => {
  3. if (typeof url !== 'string') {
  4. throw new TypeError(`Expected a \`string\`, got \`${typeof url}\``);
  5. }
  6. // Don't match Windows paths `c:\`
  7. if (/^[a-zA-Z]:\\/.test(url)) {
  8. return false;
  9. }
  10. // Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
  11. // Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
  12. return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url);
  13. };