UNPKG

@datadog/mobile-react-native

Version:

A client-side React Native module to interact with Datadog

36 lines (33 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.URLHostParser = void 0; var _InternalLog = require("../../../../../InternalLog"); var _SdkVerbosity = require("../../../../../SdkVerbosity"); /* * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. * This product includes software developed at Datadog (https://www.datadoghq.com/). * Copyright 2016-Present Datadog, Inc. */ // matches what is between the first "://" and the next "/", ":" or whitespace const hostRegex = '^.+://([^:/\\s]+)'; /** * Returns the host from an URL. * @returns the host (without the port) or null if could not cast the URL as host */ const URLHostParser = url => { try { const matchedHost = url.match(hostRegex); if (matchedHost === null) { return null; } // [0] is the input, [1] is the captured group return matchedHost[1]; } catch (e) { _InternalLog.InternalLog.log(`Impossible to cast ${url} as URL`, _SdkVerbosity.SdkVerbosity.WARN); return null; } }; exports.URLHostParser = URLHostParser; //# sourceMappingURL=URLHostParser.js.map