MCPcopy Create free account
hub / github.com/dailydotdev/apps / isImageUrl

Function isImageUrl

packages/shared/src/lib/image.ts:7–30  ·  view source on GitHub ↗
(
  url: string,
  baseUrl = globalThis.location?.href ?? 'https://daily.dev',
)

Source from the content-addressed store, hash-verified

5const CLOUDINARY_IMAGE_HOST_PATTERN = /(^|\.)cloudinary\.com$/;
6
7export const isImageUrl = (
8 url: string,
9 baseUrl = globalThis.location?.href ?? 'https://daily.dev',
10): boolean => {
11 if (!url) {
12 return false;
13 }
14
15 try {
16 const parsedUrl = new URL(url, baseUrl);
17 const host = parsedUrl.hostname.toLowerCase();
18
19 if (
20 (host === DAILY_MEDIA_HOST || CLOUDINARY_IMAGE_HOST_PATTERN.test(host)) &&
21 parsedUrl.pathname.includes('/image/')
22 ) {
23 return true;
24 }
25
26 return IMAGE_FILE_EXTENSION_PATTERN.test(parsedUrl.pathname);
27 } catch {
28 return false;
29 }
30};
31
32export const cloudinaryPostImageCoverPlaceholder =
33 'https://media.daily.dev/image/upload/s--P4t4XyoV--/f_auto/v1722860399/public/Placeholder%2001';

Callers 3

shouldOpenAnchorImageFunction · 0.90
MarkdownFunction · 0.90
image.spec.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected