2021-12-07 13:18:08 -05:00

13 lines
315 B
JavaScript

const url = require('url');
const { strict: assert } = require('assert');
module.exports = (target) => {
try {
const { protocol } = new url.URL(target);
assert(protocol.match(/^(https?:)$/));
return true;
} catch (err) {
throw new TypeError('only valid absolute URLs can be requested');
}
};