# yatra/3.0.13/resources/js/lib/attachment.ts

Yatra – Travel Booking &amp; Tour Operator Software, version 3.0.13. 51 lines.

- Page: https://pluginprobe.com/plugins/yatra/3.0.13/code/resources/js/lib/attachment.ts
- Raw: https://pluginprobe.com/plugins/yatra/3.0.13/raw/resources/js/lib/attachment.ts
- Modified: 2026-04-14T03:47:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/yatra/3.0.13/code/resources/js/lib/attachment.ts#L10-L20`.

```typescript
/**
 * Attachment utility functions
 * Handles conversion between attachment IDs and URLs
 */

/**
 * Get image URL from attachment ID
 * @param attachmentId - WordPress attachment ID
 * @returns Image URL or null if invalid
 */
export const getAttachmentUrl = (
  attachmentId: string | number | null | undefined,
): string | null => {
  if (!attachmentId) return null;

  const id = String(attachmentId);

  // If it's already a URL (for backward compatibility), return it
  if (id.startsWith("http://") || id.startsWith("https://")) {
    return id;
  }

  // If it's a numeric attachment ID, use wp_get_attachment_image_url
  // This will be handled by the backend API
  // For frontend, we'll use a REST API endpoint or inline script
  if (/^\d+$/.test(id)) {
    // Use WordPress REST API to get attachment URL
    // For now, return null and let the backend handle it
    // The backend should convert attachment IDs to URLs
    return null;
  }

  return null;
};

/**
 * Check if a value is an attachment ID (numeric string)
 */
export const isAttachmentId = (value: string | null | undefined): boolean => {
  if (!value) return false;
  return /^\d+$/.test(String(value));
};

/**
 * Check if a value is a URL
 */
export const isUrl = (value: string | null | undefined): boolean => {
  if (!value) return false;
  return value.startsWith("http://") || value.startsWith("https://");
};

```
