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.3 to 1.0.4

dist/index.js

8

index.js

@@ -1,2 +0,2 @@

import { get as getStorage, save as saveStorage, clear as clearStorage } from './utils/localstorage'
import { get as getStorage, save as saveStorage, clear as clearStorage, listen as listenStorage } from './utils/localstorage'

@@ -19,3 +19,5 @@ const list = () => getStorage();

const onChange = (cb) => isCallback(cb) ? listenStorage(cb) : console.log(typeof cb)
const isValid = (product) => product.id && product.price

@@ -27,4 +29,4 @@

const isCallback = (cb) => cb && typeof cb === Function
const isCallback = (cb) => cb && typeof cb === "function"
export { list, get, add, remove, update, total, destroy, exists, subtotal };
export { list, get, add, remove, update, total, destroy, exists, subtotal, onChange };
{
"name": "cart-localstorage",
"version": "1.0.3",
"version": "1.0.4",
"description": "Tiny shopping cart on top of LolcalStorage - ES6, < 1Kb, test coverage",
"main": "index.js",
"scripts": {
"test": "jest"
"test": "jest",
"build": "rollup index.js --file dist/index.js --format iife --name cartLS"
},

@@ -31,4 +32,5 @@ "repository": {

"babel-loader": "^8.0.5",
"jest": "^24.5.0"
"jest": "^24.5.0",
"rollup": "^1.7.4"
}
}
const STORAGE_KEY = '__cart'
let saveListener = null;
export const listen = (cb) => { saveListener = cb }; // ugly but storage listener is not working for the same window..
export const get = (key) => JSON.parse(localStorage.getItem(key || STORAGE_KEY)) || [];
export const save = (data, key) => localStorage.setItem(key || STORAGE_KEY, JSON.stringify(data));
export const save = (data, key) => {
localStorage.setItem(key || STORAGE_KEY, JSON.stringify(data));
if(saveListener) saveListener(get(key || STORAGE_KEY))
}
export const clear = () => localStorage.removeItem(STORAGE_KEY)

Sorry, the diff of this file is not supported yet

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