shop6
1import type { CartItem } from "./cart"
2
3const TAX_RATE = 0.2
4
5// Prices stay in cents until they're shown, so they never drift.
6export function totalPrice(items: CartItem[]) {
7 const subtotal = items.reduce(
8 (sum, item) => sum + item.price * item.quantity,
9 0
10 )
11 return Math.round(subtotal * (1 + TAX_RATE))
12}
13
14export function formatPrice(cents: number) {
15 return new Intl.NumberFormat("en-GB", {
16 style: "currency",
17 currency: "GBP",
18 }).format(cents / 100)
19}