Skip to content

Latest commit

 

History

History
143 lines (102 loc) · 3.19 KB

readme.md

File metadata and controls

143 lines (102 loc) · 3.19 KB

Shopping Cart App

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.

Features

  • Add items to the cart
  • Remove items from the cart
  • Update item quantities
  • Calculate total cost
  • Persist cart items across sessions

Installation


npm install shopping-cart-app

Usage

First, import the required functions from the library:


const { addItem, removeItem, updateItemQuantity, calculateTotal, getCartItems } = require('shopping-cart-app');

Adding Items

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));

Removing Items

Use the removeItem function to remove an item from the cart:


removeItem('item1')
  .then(cart => console.log(cart))
  .catch(error => console.error(error));

Updating Item Quantities

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));

Calculating Total Cost

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));

Getting Cart Items

Use the getCartItems function to get all items in the cart:


getCartItems()
  .then(cart => console.log(cart))
  .catch(error => console.error(error));

API

addItem(name, quantity, price)

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.

removeItem(name)

Removes an item from the cart.

  • name (string): The name of the item to remove.
  • Returns: A promise that resolves to the updated cart.

updateItemQuantity(name, quantity)

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.

calculateTotal()

Calculates the total cost of items in the cart.

  • Returns: A promise that resolves to the total cost.

getCartItems()

Gets all items in the cart.

  • Returns: A promise that resolves to the cart items.

License

This project is licensed under the MIT License.