Welcome to the Shopping Cart App. This application provides a simple and efficient way to manage items in a shopping cart, allowing users to add, remove, and update items seamlessly.
- Add items to the cart
- Remove items from the cart
- Update item quantities
- Calculate total cost
- Persist cart items across sessions
npm install shopping-cart-app
First, import the required functions from the library:
const { addItem, removeItem, updateItemQuantity, calculateTotal, getCartItems } = require('shopping-cart-app');
Use the addItem
function to add an item to the cart:
addItem('item1', 2, 9.99)
.then(cart => console.log(cart))
.catch(error => console.error(error));
Use the removeItem
function to remove an item from the cart:
removeItem('item1')
.then(cart => console.log(cart))
.catch(error => console.error(error));
Use the updateItemQuantity
function to update the quantity of an item in the cart:
updateItemQuantity('item1', 3)
.then(cart => console.log(cart))
.catch(error => console.error(error));
Use the calculateTotal
function to calculate the total cost of items in the cart:
calculateTotal()
.then(total => console.log('Total cost:', total))
.catch(error => console.error(error));
Use the getCartItems
function to get all items in the cart:
getCartItems()
.then(cart => console.log(cart))
.catch(error => console.error(error));
Adds an item to the cart.
- name (string): The name of the item.
- quantity (number): The quantity of the item.
- price (number): The price of the item.
- Returns: A promise that resolves to the updated cart.
Removes an item from the cart.
- name (string): The name of the item to remove.
- Returns: A promise that resolves to the updated cart.
Updates the quantity of an item in the cart.
- name (string): The name of the item.
- quantity (number): The new quantity of the item.
- Returns: A promise that resolves to the updated cart.
Calculates the total cost of items in the cart.
- Returns: A promise that resolves to the total cost.
Gets all items in the cart.
- Returns: A promise that resolves to the cart items.
This project is licensed under the MIT License.