UNPKG

580 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = throwIfNonAllowedProtocol;
7/**
8 * Check if a url uses an allowed protocol
9 */
10
11const ALLOWED_PROTOCOLS = ['http:', 'https:', 'devtools:', 'flipper:'];
12function throwIfNonAllowedProtocol(url) {
13 const _url = new URL(url);
14 const urlProtocol = _url.protocol;
15 if (!ALLOWED_PROTOCOLS.includes(urlProtocol)) {
16 throw new Error(`Invalid url protocol ${urlProtocol}.\nAllowed protocols: ${ALLOWED_PROTOCOLS.join(', ')}`);
17 }
18}
19
20//# sourceMappingURL=throwIfNonAllowedProtocol.ts.map
\No newline at end of file