MCPcopy Create free account
hub / github.com/Snapchat/Valdi / makeURL

Function makeURL

src/valdi_modules/src/valdi/valdi_http/src/HTTPClient.ts:7–22  ·  view source on GitHub ↗
(baseUrl: string | undefined, pathOrUrl: string)

Source from the content-addressed store, hash-verified

5import { performRequest } from './NativeHTTPClient';
6
7function makeURL(baseUrl: string | undefined, pathOrUrl: string): string {
8 if (pathOrUrl.indexOf('://') >= 0) {
9 return pathOrUrl;
10 }
11 if (!baseUrl) {
12 throw new Error('baseUrl should be specified when providing a relative path');
13 }
14
15 if (!baseUrl.endsWith('/')) {
16 baseUrl += '/';
17 }
18 if (pathOrUrl.startsWith('/')) {
19 pathOrUrl = pathOrUrl.substring(1);
20 }
21 return baseUrl + pathOrUrl;
22}
23
24export class HTTPClient implements IHTTPClient {
25 constructor(readonly baseUrl?: string | undefined) {}

Callers 1

performMethod · 0.85

Calls 3

startsWithMethod · 0.80
substringMethod · 0.80
indexOfMethod · 0.45

Tested by

no test coverage detected