basket-helper
A simple utility class for managing baskets in node js
install
npm install basket-helper
## usage
first require the module
var BH =
add a config file and pass it to the basket helper
var config = "validateItems" : true //check if products exist in the list of products before adding them "currency": "£" // currency for display purposes "products" : "name" : "apple" // product name "price" : 020 // product price "name" : "orange" "price" : 030 "name" : "garlic" "price" : 015 "name" : "papaya" "price" : 05 "promotions": // an array of promotions "type": "buyXofferY" //the type of the promotion "product": "papaya" // the products on which the promo applicable "buy": 6 // how much products to buy to trigger the promo "offer": 2 // how much products are offers var bHelp = config // pass config object
addAll with a list of product names
bHelp bHelp
pass products individualy with add method
bHelpbHelp
total
use total function to calculate the cart total it returns an object with a msg properties displaying a kinda bill and the sum of all products prices in the total property
processstdout
you can open exemple.js file to see basic exemple of usage
Contribute
download the source from git hub then in the directory of the project run :
npm run dev
make your changes in src directory, and nodemon will trigger babel compiling notice that app.js is a dummy app for testing purposes in production it's basketHelper.js that is exported