All files / src/helpers url.ts

100% Statements 5/5
100% Branches 5/5
100% Functions 0/0
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14  50x 50x         185x 175x   10x      
export function safelyAppendUrlParameter (url: string, parameterKey: string, parameterValue: string): string {
  const separator = url.includes('?') ? '&' : '?';
  return `${url}${separator}${parameterKey}=${parameterValue}`;
}
 
export function isValidUrl (url: string): boolean {
  try {
    const parsedUrl = new URL(url);
    return !parsedUrl.pathname.includes(' ') && !parsedUrl.hostname.includes(' ') && url.includes(':');
  } catch {
    return false;
  }
}