formatAttachmentSize (utils/attachment-utils.ts)

vellum-assistant · clients/web/src/utils/attachment-utils.ts · typescript · MIT
files, Files / Storage

Utility functions to format attachment sizes, detect image types, and classify attachments for UI rendering.

// Source: https://github.com/vellum-ai/vellum-assistant | License: MIT | Copyright 2025 Vellum AI
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Presentation helpers every attachment and file surface shares: the size
 * string, the middle-truncated filename, the image test the vision gate
 * reads, and the icon kind a file classifies as.
 *
 * Pure derivations over a name, a type, and a byte count, so a surface
 * outside chat can render a file the same way the transcript does without
 * reaching into chat.
 */

import {
  Archive,
  Code2,
  FileAudio,
  File as FileIcon,
  FileImage,
  FileSpreadsheet,
  FileText,
  FileType2,
  FileVideo,
  type LucideIcon,
} from "lucide-react";

import {
  baseMimeType,
  extensionOf,
  GENERIC_MIME_TYPES,
} from "@/utils/mim

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key