Socket
Socket
Sign inDemoInstall

cart-localstorage

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

4

index.js

@@ -9,3 +9,3 @@ import { get as getStorage, save as saveStorage, clear as clearStorage } from './utils/localstorage'

const add = (product, quantity) => exists(product.id) ? update(product.id, 'quantity', get(product.id).quantity + (quantity || 1)) : saveStorage(getStorage().concat({ ...product, quantity: quantity || 1 }));
const add = (product, quantity) => isValid(product) ? exists(product.id) ? update(product.id, 'quantity', get(product.id).quantity + (quantity || 1)) : saveStorage(getStorage().concat({ ...product, quantity: quantity || 1 })) : null;

@@ -21,2 +21,4 @@ const remove = (id) => saveStorage(getStorage().filter((product) => product.id !== id))

const isValid = (product) => product.id && product.price
const subtotal = (product) => isCalcable(product) ? (product.price * product.quantity) : 0

@@ -23,0 +25,0 @@

{
"name": "cart-localstorage",
"version": "1.0.2",
"version": "1.0.3",
"description": "Tiny shopping cart on top of LolcalStorage - ES6, < 1Kb, test coverage",

@@ -5,0 +5,0 @@ "main": "index.js",

# cart-localstorage
Super simple shopping cart library
#### Super simple JavaScript shopping cart library
This library utilizes the browser's localStorage and creates a persistent shopping cart instance during the first add(product) call.
## Install:

@@ -7,0 +9,0 @@

@@ -65,2 +65,22 @@

it('should not add product to the cart without id', () => {
getLocalStorage.mockReturnValue(CART_0);
add({ name: "c", price: 100 });
expect(saveLocalStorage).not.toHaveBeenCalled();
});
it('should not add product to the cart without price', () => {
getLocalStorage.mockReturnValue(CART_0);
add({ name: "c", id: 10 });
expect(saveLocalStorage).not.toHaveBeenCalled();
});
it('should add the new product to the empty cart', () => {

@@ -117,3 +137,2 @@

})

@@ -159,3 +178,3 @@

update(1,"quantity", 5);
update(1, "quantity", 5);
expect(saveLocalStorage).toBeCalledWith([{ ...PRODUCT_1, quantity: 5 }, PRODUCT_2]);

@@ -169,3 +188,3 @@

update(2,"quantity", 3);
update(2, "quantity", 3);

@@ -180,3 +199,3 @@ expect(saveLocalStorage).toBeCalledWith(CART_1);

update(1,"quantity", -1);
update(1, "quantity", -1);
expect(saveLocalStorage).toBeCalledWith(CART_1);

@@ -183,0 +202,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc