const FA_DIGITS = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]; export function toFaDigits(input: string | number): string { return String(input).replace(/\d/g, (d) => FA_DIGITS[Number(d)]); } // Prices come from the API in Toman. export function formatPrice(value: number | null | undefined): string { if (value === null || value === undefined) return ""; return toFaDigits(value.toLocaleString("en-US")); } export function discountPercent(price: number, oldPrice: number): number { if (!oldPrice || oldPrice <= price) return 0; return Math.round(((oldPrice - price) / oldPrice) * 100); } // Per AI_PROMPT.md "Shopping cart" step 3: a variant's stockQuantity of // `null` means unlimited stock (in stock), not zero/out of stock — never // treat it as falsy. export function isInStock(stockQuantity: number | null | undefined): boolean { return stockQuantity === null || (stockQuantity ?? 0) > 0; } // The static-image-slot API documents aspectRatio as "16:9", but CSS's // aspect-ratio property needs a slash ("16/9"), not a colon. export function toCssAspectRatio(value: string | number | null | undefined): string | undefined { if (value === null || value === undefined || value === "") return undefined; return String(value).replace(":", "/"); }