npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

basket-helper

v1.0.4

Published

help you managing baskets

Downloads

8

Readme

basket-helper

A simple utility class for managing baskets in node js

install

  npm install basket-helper

usage

first require the module

var BH = require("basket-helper")

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" : 0.20	// product price
		},
		{
			"name" : "orange",
		 	"price" : 0.30
		},
		{
			"name" : "garlic",
			"price" : 0.15
		},
		{
			"name" : "papaya",
		 	"price" : 0.5
		}
	],
	"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 = new BH(config) // pass config object

addAll with a list of product names

bHelp.addAll([
	"papaya", 
	"papaya", 
	"papaya", 
	"papaya", 
	"papaya", 
	"papaya"
])

bHelp.addAll([
	{"name" : "garlic", "qt" : 3, "price":5 }, // you can also optionaly pass quantity and price. 
	//it you do not have validation function on you have to pass a price at least the 1st time you add a product name differently
	{"name" : "apple"} // or simply a name
])

pass products individualy with add method

bHelp.add("papaya")
bHelp.add("Orange", 2)

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

process.stdout.write(bHelp.total().msg)

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