Cartify
Shopping cart management library

⚠️ Expect some breaking changes, Use at your own risk
:package: Requirements
- Node.js 16X LTS or Higher 📦
:sparkles: Installation
- Install using the below command (with your package manager of choice)
npm install cartify --save
yarn add cartify
pnpm add cartify
bun install cartify
:bulb: Usage Example
import { useCartify } from "cartify";
const cart = useCartify();
const demoItem = {
productId: "123",
name: "Product 1",
quantity: 1,
price: 10,
};
export default function Cart() {
const add = (item) => {
cart.addToCart(item);
};
const decrease = (productId, DecreaseCount) => {
cart.decreaseItem(productId, DecreaseCount);
};
const removeFromCart = (productID) => {
cart.removeItemFromCart(productID);
};
const clear = () => {
cart.clearCart();
};
return (
<div>
<p>
Cart Items:{" "}
{cartItems.length > 0
? `${cartItems[0].name} (x${cartItems[0].quantity})`
: "No items in cart"}
</p>
<p>
Total Price:{" "}
{cartItems.length > 0
? cartItems[0].quantity * cartItems[0].price
: "N/A"}
</p>
<button onClick={() => add(demoItem)}>Add</button>
<button onClick={() => decrease("123", 1)}>Decrease</button>
<button onClick={() => removeFromCart(123)}>Remove from Cart</button>
<button onClick={() => clear()}>Clear</button>
</div>
);
}
✅ Online Demo
:green_heart: Message
I hope you find this useful. If you have any questions, please create an issue.