UNPKG

597 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = throwIfNonHttpProtocol;
7
8/**
9 * Check if a string is an http/https url
10 */
11function throwIfNonHttpProtocol(url) {
12 const _url = new URL(url);
13
14 const urlProtocol = _url.protocol;
15 const expectedProtocol = {
16 [urlProtocol]: false,
17 'http:': true,
18 'https:': true
19 };
20 const isFromExpectedProtocol = expectedProtocol[urlProtocol];
21
22 if (!isFromExpectedProtocol) {
23 throw new Error('invalid url, missing http/https protocol');
24 }
25}
26
27//# sourceMappingURL=throwIfNonHttpProtocol.js.map
\No newline at end of file