UNPKG

auto-gpt-ts

Version:

my take of Auto-GPT in typescript

64 lines 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sanitizeUrl = exports.isValidUrl = void 0; const url_1 = require("url"); function isValidUrl(url) { /** * Check if the URL is valid * @param {string} url - The URL to check * @returns {boolean} True if the URL is valid, False otherwise */ try { const { protocol, host } = new url_1.URL(url); return !!(protocol && host); } catch (e) { return false; } } exports.isValidUrl = isValidUrl; function sanitizeUrl(url) { /** * Sanitize the URL * @param {string} url - The URL to sanitize * @returns {string} The sanitized URL */ const { pathname, hash, searchParams } = new url_1.URL(url); const queryParams = searchParams.toString() ? `?${searchParams}` : ""; return `${pathname}${queryParams}${hash}`; } exports.sanitizeUrl = sanitizeUrl; function checkLocalFileAccess(url) { /** * Check if the URL is a local file * @param {string} url - The URL to check * @returns {boolean} True if the URL is a local file, False otherwise */ const localPrefixes = [ "file:///", "file://localhost/", "file://localhost", "http://localhost", "http://localhost/", "https://localhost", "https://localhost/", "http://2130706433", "http://2130706433/", "https://2130706433", "https://2130706433/", "http://127.0.0.1/", "http://127.0.0.1", "https://127.0.0.1/", "https://127.0.0.1", "https://0.0.0.0/", "https://0.0.0.0", "http://0.0.0.0/", "http://0.0.0.0", "http://0000", "http://0000/", "https://0000", "https://0000/", ]; return localPrefixes.some((prefix) => url.startsWith(prefix)); } //# sourceMappingURL=validators.js.map