Socket
Socket
Sign inDemoInstall

cart-localstorage

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cart-localstorage - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

package.json
{
"name": "cart-localstorage",
"version": "1.0.1",
"version": "1.0.2",
"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 with a very small footprint (~1Kb, 0 dependencies)
Super simple shopping cart library
This library utilizes the browser's localStorage and creates a persistent shopping cart instance during the first add(product) call.
## Demo
//todo
## Install:

@@ -16,10 +12,9 @@

npm install cart-localstorage
```
or
```
yarn add cart-localstorage
```
## How to start?
## Example

@@ -29,21 +24,27 @@ ```

add({id: 1, name: "Product 1", price: 100}, 1)
add({id: 1, name: "Product 1", price: 100})
add({id: 2, name: "Product 2", price: 100}, 2)
console.log(total())
// output: 100
...
// output: 300
```
## Features
## Demo
#### add(<product>, <quantity>)
//todo
Adds product into the cart. If the product already exists with the same id increases the quantity.
## API
#### add(product, [quantity:1])
Adds a product into the cart. If the product is already exists (same id) it increases the quantity with +1.
"Product" should be a JavaScript object with "id" and "price" properties.
```
add({id: 3, name: "Vans", price: 75}, 2)
const myproduct = {id: 3, name: "Vans", price: 75}
add(myproduct, 2)
```
#### get(<id>)
#### get(id)

@@ -57,3 +58,3 @@ Get product by id

#### exists(<id>)
#### exists(id)

@@ -76,3 +77,3 @@ Checks if the product is already exists in the cart

#### remove(<id>)
#### remove(id)

@@ -85,3 +86,3 @@ Removes the product from the cart

#### update(<id>, <field>, <valud>)
#### update(id, field, value)

@@ -93,3 +94,3 @@ Updates product's field with a certain value.

#### total(<callback>)
#### total([reducer])

@@ -96,0 +97,0 @@ By default it returns with the total price:

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc