1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.isLocal = exports.isInternalIP = exports.toProtocol = exports.stripSlashEnd = exports.stripSlashStart = exports.stripSlash = exports.stripPort = exports.stripHttp = exports.toPort = void 0;
|
4 | var common_1 = require("../common");
|
5 | function toPort(input) {
|
6 | var text = common_1.R.pipe(stripHttp, stripSlash)(input || '').split(':')[1];
|
7 | return text === undefined ? undefined : common_1.value.toNumber(text);
|
8 | }
|
9 | exports.toPort = toPort;
|
10 | function stripHttp(input) {
|
11 | return (input || '')
|
12 | .trim()
|
13 | .replace(/^http\:\/\//, '')
|
14 | .replace(/^https\:\/\//, '');
|
15 | }
|
16 | exports.stripHttp = stripHttp;
|
17 | function stripPort(input) {
|
18 | return (input || '').replace(/\:\d*$/, '');
|
19 | }
|
20 | exports.stripPort = stripPort;
|
21 | function stripSlash(input) {
|
22 | return (input || '').replace(/^\/*/, '').replace(/\/*$/, '');
|
23 | }
|
24 | exports.stripSlash = stripSlash;
|
25 | function stripSlashStart(input) {
|
26 | return (input || '').replace(/^\/*/, '');
|
27 | }
|
28 | exports.stripSlashStart = stripSlashStart;
|
29 | function stripSlashEnd(input) {
|
30 | return (input || '').replace(/\/*$/, '');
|
31 | }
|
32 | exports.stripSlashEnd = stripSlashEnd;
|
33 | function toProtocol(input) {
|
34 | input = (input || '').trim();
|
35 | if (input.startsWith('localhost') && !input.includes('.')) {
|
36 | return 'http';
|
37 | }
|
38 | if (isInternalIP(input)) {
|
39 | return 'http';
|
40 | }
|
41 | return 'https';
|
42 | }
|
43 | exports.toProtocol = toProtocol;
|
44 | function isInternalIP(input) {
|
45 | var host = common_1.R.pipe(stripHttp, stripSlash)(input || '').split('/')[0] || '';
|
46 | return host.startsWith('192.168.');
|
47 | }
|
48 | exports.isInternalIP = isInternalIP;
|
49 | function isLocal(input) {
|
50 | if (isInternalIP(input)) {
|
51 | return true;
|
52 | }
|
53 | var host = stripSlash(stripHttp(input)).split('/')[0] || '';
|
54 | if (host === 'localhost' || host.startsWith('localhost:')) {
|
55 | return true;
|
56 | }
|
57 | return false;
|
58 | }
|
59 | exports.isLocal = isLocal;
|