cart-localstorage
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -9,3 +9,3 @@ var cartLS = (function (exports) { | ||
const get = (key) => JSON.parse(localStorage.getItem(key || STORAGE_KEY)) || []; | ||
const list = (key) => JSON.parse(localStorage.getItem(key || STORAGE_KEY)) || []; | ||
@@ -22,16 +22,16 @@ const save = (data, key) => { | ||
const list = () => get(); | ||
const get$1 = (id) => list().find((product) => product.id === id); | ||
const get$1 = (id) => get().find((product) => product.id === id); | ||
const exists = (id) => !!get$1(id); | ||
const add = (product, quantity) => isValid(product) ? exists(product.id) ? update(product.id, 'quantity', get$1(product.id).quantity + (quantity || 1)) : save(get().concat({ ...product, quantity: quantity || 1 })) : null; | ||
const add = (product, quantity) => isValid(product) ? exists(product.id) ? update(product.id, 'quantity', get$1(product.id).quantity + (quantity || 1)) : save(list().concat({ ...product, quantity: quantity || 1 })) : null; | ||
const remove = (id) => save(get().filter((product) => product.id !== id)); | ||
const remove = (id) => save(list().filter((product) => product.id !== id)); | ||
const update = (id, field, value) => save(get().map((product) => product.id === id ? ({ ...product, [field]: value }) : product)); | ||
const quantity = (id, diff) => exists(id) && get$1(id).quantity + diff >= 0 ? update(id, 'quantity', get$1(id).quantity + diff) : remove(id); | ||
const total = (cb) => get().reduce((sum, product) => isCallback(cb) ? cb(sum, product) : (sum += subtotal(product)), 0); | ||
const update = (id, field, value) => save(list().map((product) => product.id === id ? ({ ...product, [field]: value }) : product)); | ||
const total = (cb) => list().reduce((sum, product) => isCallback(cb) ? cb(sum, product) : (sum += subtotal(product)), 0); | ||
const destroy = () => clear(); | ||
@@ -56,2 +56,3 @@ | ||
exports.onChange = onChange; | ||
exports.quantity = quantity; | ||
exports.remove = remove; | ||
@@ -58,0 +59,0 @@ exports.subtotal = subtotal; |
{ | ||
"name": "cart-localstorage", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Tiny shopping cart on top of LolcalStorage - ES6, < 1Kb, test coverage", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18226
266