pos-dashboard-v2/src/utils/transform.ts

34 lines
887 B
TypeScript
Raw Normal View History

2025-08-07 14:31:42 +07:00
export const formatCurrency = (amount: number) => {
return new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0
}).format(amount)
}
2025-08-08 17:59:39 +07:00
export const formatShortCurrency = (num: number): string => {
if (num >= 1_000_000) {
return (num / 1_000_000).toFixed(2) + 'M'
} else if (num >= 1_000) {
return (num / 1_000).toFixed(2) + 'k'
}
return num.toString()
}
2025-08-07 14:31:42 +07:00
export const formatDate = (dateString: string) => {
return new Date(dateString).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
})
}
2025-08-07 23:48:31 +07:00
export const formatDateDDMMYYYY = (date: Date) => {
2025-08-08 17:59:39 +07:00
const day = String(date.getDate()).padStart(2, '0')
const month = String(date.getMonth() + 1).padStart(2, '0')
const year = date.getFullYear()
return `${day}-${month}-${year}`
}