All files / src/utils image.helpers.ts

77.77% Statements 7/9
75% Branches 6/8
100% Functions 2/2
100% Lines 6/6

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 15 16 17 18 19 20 21 22 23 24              929x   929x   132x           660x   132x   132x    
type TImageSize = "small" | "medium" | "large" | "thumb" | "original";
 
export function addSizeToImage(
  url: string,
  size: TImageSize,
  fallback?: string,
) {
  Iif (!url && fallback) return fallback;
 
  if (!url) return "";
 
  const urlIncludesSize = [
    "/small",
    "/large",
    "/medium",
    "/original",
    "/thumb",
  ].some((substring) => url.includes(substring));
 
  Iif (urlIncludesSize) return url;
 
  return url + "/" + size;
}