UNPKG

@sap-cloud-sdk/util

Version:

SAP Cloud SDK for JavaScript general utilities

34 lines 962 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isValidUrl = isValidUrl; exports.checkUrlExists = checkUrlExists; const axios_1 = __importDefault(require("axios")); /** * Checks whether a string is a valid URL. * @param url - String to check. * @returns True if the string is a valid URL, false otherwise. * @internal */ function isValidUrl(url) { try { new URL(url); return true; } catch { return false; } } /** * Checks whether a URL is existing via a head request. * @param url - URL to be checked. * @returns Promise - resolves if the URL exists. */ async function checkUrlExists(url) { return axios_1.default .request({ url, method: 'HEAD' }) .then(response => response.status); } //# sourceMappingURL=url.js.map