mirror of
https://git.meshkee.com/Meshkee/dashboards.git
synced 2026-08-12 06:40:57 +04:30
Includes business, customer, and super-admin apps with shared packages and production deploy scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
40 lines
1.1 KiB
TypeScript
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)
|
|
}
|