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

cornershop

v0.5.0

Published

Shopping cart that saves to LocalStorage.

Downloads

17

Readme

cornershop

Shopping cart that saves to LocalStorage.

installation

npm/browserify:

$ npm install cornershop

component:

$ component install binocarlos/cornershop

usage

cart access

Each cart has a name - this is used for the localstorage variable name and so you can have as many carts as you want.

var shop = require('cornershop');
var cart = shop('mystoreid');

load()

To load the cart from localstorage either pass true as the second argument:

var shop = require('cornershop');
var cart = shop('mystoreid', true);

or call the .load method manually:

var shop = require('cornershop');
var cart = shop('mystoreid');
cart.load();

save()

To save the cart to localstorage call the .save() method:

var shop = require('cornershop');
var cart = shop('mystoreid');
cart.load();

// do stuff

cart.save();

items

The cart works on a list of items. An item is a plain JavaScript object with these properties:

  • id (10)
  • name (Superman Poster)
  • price (12.5)
  • qty (2)

You can add any meta-data to an item that you want, for example a description and image:

  • desc (10x5 - superman logo bottom-right)
  • image (/img/shop/superman.png)

Access the items in the cart:

// an array of items
var items = cart.items;

var item = items[0];
console.log(item);

/*
{
	id:10,
	name:'Superman Poster',
	desc:'10x5 - superman logo bottom-right',
	price:12.5,
	qty:2,
	image:'/img/shop/superman.png'
}
*/

addItem({...})

To add a new item to the cart:

cart.addItem({
	id:10,
	name:'Superman Poster',
	desc:'10x5 - superman logo bottom-right',
	price:12.5,
	qty:2,
	image:'/img/shop/superman.png'
})

getItem(id)

To edit an item you fetch it by id and change properties of the item object and then save the cart.

var item = cart.getItem(10);
item.qty++;
cart.save();

removeItem(id)

Remove an item with an id - this auto-saves:

cart.removeItem(10);

getTotal(withExtras)

The cart will return the current total - this is based on item.price * item.qty:

var total = cart.getTotal();
var totalwithshipping = cart.getTotal(true);

extras

This accounts for extra things like shipping and any other things that are not products but have a charge associated.

setExtra(field, {...})

Add an extra item to the cart - like shipping.

Each extra item should have a 'name', 'price' and 'qty' field like the products.

cart.setExtra('shipping', {
	name:'Shipping UK - 5 day',
	price:12
})

removeExtra(field)

Remove an extra field

cart.removeExtra('shipping');

getExtras()

Return an array of the extra settings in the cart:

var extra_array = cart.getExtras();

getExtraTotal()

Return the sub-total just for the extra items

License

MIT