Package Exports
- node-cart-test
- node-cart-test/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-cart-test) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
easy-cart
A simple, lightweight e-commerce cart utility for Node.js and browsers.
Installation
npm install easy-cart
Usage
const {
addItem,
removeItem,
getCartSummary,
DISCOUNT_TYPES
} = require('easy-cart');
// Create a cart
let cart = [];
cart = addItem(cart, { id: 1, name: "T-Shirt", price: 19.99 });
cart = addItem(cart, { id: 2, name: "Mug", price: 9.99, quantity: 2 });
// Apply discount
const discount = { type: DISCOUNT_TYPES.PERCENT, value: 10 }; // 10% off
// Get summary
const summary = getCartSummary(cart, discount, { freeThreshold: 50 });
console.log(summary);
/*
{
subtotal: 39.97,
discount: 3.997,
shipping: 0,
total: 35.973
}
*/
API
Core Functions
addItem(cart, item)
- Add/update item in cartremoveItem(cart, id)
- Remove item from cartupdateQuantity(cart, id, quantity)
- Update item quantitygetSubtotal(cart)
- Calculate cart subtotalapplyDiscount(amount, discount)
- Apply discount to amountcalculateShipping(subtotal, options)
- Calculate shipping costgetCartSummary(cart, discount, shippingOptions)
- Get complete cart summary
Constants
DISCOUNT_TYPES
- Available discount types (PERCENT, FIXED, FREE_SHIPPING)
License
MIT