JSPM

node-cart-test

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 2
    • Score
      100M100P100Q17570F
    • License MIT

    A simple, lightweight e-commerce cart utility

    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 cart
    • removeItem(cart, id) - Remove item from cart
    • updateQuantity(cart, id, quantity) - Update item quantity
    • getSubtotal(cart) - Calculate cart subtotal
    • applyDiscount(amount, discount) - Apply discount to amount
    • calculateShipping(subtotal, options) - Calculate shipping cost
    • getCartSummary(cart, discount, shippingOptions) - Get complete cart summary

    Constants

    • DISCOUNT_TYPES - Available discount types (PERCENT, FIXED, FREE_SHIPPING)

    License

    MIT