-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add cart totals module and cat color helpers #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| export function subtotal(items) { | ||
| return items.reduce((sum, item) => sum + item.price * item.quantity, 0); | ||
| } | ||
|
|
||
| export function applyDiscount(amount, percent) { | ||
| if (percent < 0 || percent > 100) { | ||
| throw new RangeError("percent must be between 0 and 100"); | ||
| } | ||
|
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NaN discount yields invalid totals
Want Baz to fix this for you? Activate Fixer Prompt for AI Agents |
||
| return amount * (1 - percent / 100); | ||
| } | ||
|
|
||
| export function total(items, discountPercent = 0) { | ||
| return applyDiscount(subtotal(items), discountPercent); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cart module fails on supported Node runtimes
cart.jsuses ESM syntax butnode/package.jsondoesn't declare"type": "module", so Node 18+ treats it as CommonJS and throws a syntax error on import — should we add"type": "module"or rewrite it as CommonJS?Want Baz to fix this for you? Activate Fixer
Prompt for AI Agents