
Security News
CISA Kills Off RSS Feeds for KEVs and Cyber Alerts
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
cart-localstorage
Advanced tools
Tiny shopping cart on top of LolcalStorage - ES6, < 1Kb, full test coverage
This micro library utilizes the browser's localStorage to create a persistent shopping cart instance
Use npm or yarn to add it to your ES6 project:
npm install cart-localstorage
yarn add cart-localstorage
OR use the bundled version (via CDN):
<script src="https://unpkg.com/cart-localstorage@1.1.2/dist/cart-localstorage.min.js" type="text/javascript"></script>
import { add, total } from 'cart-localstorage'
add({id: 1, name: "Product 1", price: 100})
add({id: 2, name: "Product 2", price: 100}, 2)
console.log(total())
// output: 300
Adds product to the cart. If the product already exists it increases the quantity with 1. The product object structure is flexible, only "id" and "price" are mandatory properties.
const myproduct = {id: 3, name: "Vans", price: 75}
add(myproduct, 2)
Get product from the cart by id
get(1)
// {id: 1, name: "Nike Air", price: 100, quantity: 1}
Checks if the product already exists in the cart
exists(21)
// true or false
Get the content of the cart as an array of products.
list()
// [{id: 1, name: "Nike Air", price: 100, quantity: 1}, {id: 2, name: "Adidas Superstar", price: 120, quantity: 2}]
Removes the product from the cart
remove(1)
Updates the product's property with a certain value.
update(1,'price',200)
Increase / decrease product's quantity with a positive or negative value.
quantity(22,-1) // will decrease the quantity of product [id:22] with 1.
By default returns with the total price:
total()
// 220
or you can pass a custom reducer function to have full control over the calculation.
Deletes the cart array from the browser's localStorage.
destroy()
This plugin is available under Apache 2.0 license.
FAQs
Tiny shopping cart on top of LolcalStorage - ES6, < 1Kb, full test coverage
The npm package cart-localstorage receives a total of 39 weekly downloads. As such, cart-localstorage popularity was classified as not popular.
We found that cart-localstorage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.