UNPKG

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