Files
dashboards/apps/business/src/utils/irtPrice.ts
T
Alireza HassaniandCursor f566387c61 Initial commit: Meshkee dashboards monorepo.
Includes business, customer, and super-admin apps with shared packages and production deploy scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-22 13:48:53 +03:30

40 lines
1.1 KiB
TypeScript

/** Format a numeric price for display in Iranian Toman (IRT). */
export function formatIrtPrice(value: number | null | undefined): string {
if (value === null || value === undefined) return '—'
return `${Math.round(value).toLocaleString('en-US')} IRT`
}
/** Format raw digits into comma-separated groups while typing. */
export function formatIrtInput(raw: string): string {
const digits = raw.replace(/\D/g, '')
if (!digits) return ''
return Number(digits).toLocaleString('en-US')
}
/** Parse a formatted IRT input string back to a number. */
export function parseIrtInput(formatted: string): number | null {
const digits = formatted.replace(/\D/g, '')
if (!digits) return null
return Number(digits)
}
export function hasStoreItemDiscount(
price: number | null,
discountedPrice: number | null,
): boolean {
return (
price !== null &&
discountedPrice !== null &&
discountedPrice < price &&
discountedPrice >= 0
)
}
export function calcDiscountPercent(
price: number,
discountedPrice: number,
): number {
if (price <= 0 || discountedPrice >= price) return 0
return Math.round((1 - discountedPrice / price) * 100)
}