diff --git a/CHANGES.md b/CHANGES.md index 9c38282..edf8611 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ # Changes ## Unreleased +- Add discount(items, percent): total with a percentage taken off before tax. ## 1.2.0 - total() rounds through roundCents(). diff --git a/src/lib/cart.js b/src/lib/cart.js index 385fd69..332f9ce 100644 --- a/src/lib/cart.js +++ b/src/lib/cart.js @@ -8,3 +8,7 @@ export function subtotal(items) { export function total(items) { return roundCents(subtotal(items) * (1 + TAX_RATE)); } + +export function discount(items, percent) { + return roundCents(subtotal(items) * (1 - percent / 100) * (1 + TAX_RATE)); +}