New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cart

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cart - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

lib/cart.d.ts

166

lib/cart.js

@@ -1,71 +0,103 @@

// inspired by nsession-store
var sys = require('sys');
var ConnectStore = require('connect/middleware/session/store');
var Store = require('supermarket');
module.exports = Cart;
function Cart(options) {
var self = this;
options = options || {};
options.maxAge = options.maxAge || 3600000; // Expunge after an hour
var dbFile = options.dbFile || __dirname + "/sessions.db";
ConnectStore.call(this, options);
Store({ filename : dbFile, json : true }, function (err, db) {
if (err) throw new Error(err);
self.db = db;
db.filter(
function (item) {
return item.value.lastAccess < Date.now() - options.maxAge;
}
).forEach(
function (item) {
db.remove(item.key);
}
);
});
import { useEffect, useState } from "react";
import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
const setCartStoreName = (name) => {
useCart.persist.setOptions({
name
});
};
sys.inherits(Cart, ConnectStore);
Cart.prototype.get = function (hash, fn) {
this.db.get(hash, function (err, val) {
if (err) throw new Error(err);
if (val) {
fn(null, val);
}
else {
fn();
}
})
const withSSR = (store, callback) => {
const result = store(callback);
const [data, setData] = useState();
useEffect(() => {
setData(result);
}, [result]);
return data;
};
Cart.prototype.set = function (hash, sess, fn) {
this.db.set(hash, sess, function (err) {
if (err) throw new Error(err);
if (fn) fn();
});
const setCartStoreType = (storage = localStorage) => {
useCart.persist.setOptions({
storage: createJSONStorage(() => storage)
});
};
Cart.prototype.destroy = function (hash, fn) {
this.db.remove(hash, function (err) {
if (err) throw new Error(err);
if (fn) fn();
});
const useCart = create()(
persist(
(set) => ({
addToCart: (item) => {
set((state) => {
const cartItems = state.cartItems ?? [];
const itemInCart = cartItems.find(
(i) => i.productId === item.productId
);
if (itemInCart) {
return {
cartItems: cartItems.map((i) => {
if (i.productId === item.productId) {
return { ...i, quantity: i.quantity + 1 };
}
return i;
})
};
} else {
return {
cartItems: [...cartItems, { ...item, quantity: 1 }]
};
}
});
},
cartItems: [],
clearCart: () => {
set({ cartItems: [] });
},
closeCart: () => {
set({ isCartOpen: false });
},
decreaseItem: (productId, quantity) => {
set((state) => {
if (quantity === void 0) {
return {
cartItems: state.cartItems?.filter(
(item) => item.productId !== productId
)
};
}
const updatedCartItems = state.cartItems?.map((item) => {
if (item.productId === productId) {
const newQuantity = item.quantity - quantity;
if (newQuantity <= 0) {
return null;
}
return { ...item, quantity: newQuantity };
}
return item;
}).filter(Boolean);
return { cartItems: updatedCartItems };
});
},
isCartOpen: false,
openCart: () => {
set({ isCartOpen: true });
},
removeFromCart: (productId) => {
set((state) => ({
cartItems: state.cartItems?.filter(
(item) => item.productId !== productId
)
}));
},
toggleCart: () => {
set((state) => ({ isCartOpen: !state.isCartOpen }));
}
}),
{
name: "cart",
storage: createJSONStorage(() => localStorage)
}
)
);
export {
setCartStoreName,
setCartStoreType,
useCart,
withSSR
};
Cart.prototype.length = function (fn) {
this.db.length(function (err, len) {
fn(null, len);
});
};
Cart.prototype.clear = function (fn) {
this.db.forEach(
function (item) {
this.db.remove(item.key);
}
).on('end', function () { if (fn) fn() });
};
//# sourceMappingURL=cart.js.map
{
"name" : "cart",
"version" : "1.0.4",
"description" : "Connect session store using supermarket",
"main" : "./lib/cart.js",
"keywords" : [
"connect",
"expresso",
"http sessions"
],
"author": {
"name": "Peteris Krumins",
"email": "peteris.krumins@gmail.com",
"web": "http://www.catonmat.net",
"twitter": "pkrumins"
},
"repository" : {
"type" : "git",
"url" : "http://github.com/pkrumins/supermarket-cart.git"
},
"engines": {
"node": ">=0.2.0"
},
"dependencies" : {
"supermarket" : ">=1.1.0"
}
"name": "cart",
"version": "1.1.0",
"description": "Headless cart management library",
"repository": {
"type": "git",
"url": "https://github.com/mcnaveen/cart"
},
"license": "MIT",
"author": {
"name": "mcnaveen",
"email": "me@mcnaveen.com"
},
"type": "module",
"main": "./lib/index.js",
"files": [
"lib/",
"package.json",
"LICENSE.md",
"README.md"
],
"scripts": {
"build": "tsup",
"format": "prettier \"**/*\" --ignore-unknown",
"format:write": "pnpm format --write",
"lint": "eslint . .*js --max-warnings 0 --report-unused-disable-directives",
"lint:knip": "knip",
"lint:md": "markdownlint \"**/*.md\" \".github/**/*.md\" --rules sentences-per-line",
"lint:package-json": "npmPkgJsonLint .",
"lint:packages": "pnpm dedupe --check",
"lint:spelling": "cspell \"**\" \".github/**/*\"",
"prepare": "husky install",
"should-semantic-release": "should-semantic-release --verbose",
"test": "vitest",
"tsc": "tsc"
},
"lint-staged": {
"*": "prettier --ignore-unknown --write"
},
"dependencies": {
"zustand": "^4.4.1"
},
"devDependencies": {
"@release-it/conventional-changelog": "^7.0.2",
"@types/eslint": "^8.44.2",
"@types/react": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"@vitest/coverage-v8": "^0.34.5",
"console-fail-test": "^0.2.3",
"cspell": "^7.3.6",
"eslint": "^8.49.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-jsonc": "^2.9.0",
"eslint-plugin-markdown": "^3.0.1",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-perfectionist": "^2.1.0",
"eslint-plugin-regexp": "^1.15.0",
"eslint-plugin-vitest": "^0.3.1",
"eslint-plugin-yml": "^1.9.0",
"husky": "^8.0.3",
"jsonc-eslint-parser": "^2.3.0",
"knip": "^2.25.2",
"lint-staged": "^14.0.1",
"markdownlint": "^0.31.1",
"markdownlint-cli": "^0.37.0",
"npm-package-json-lint": "^7.0.0",
"npm-package-json-lint-config-default": "^6.0.0",
"prettier": "^3.0.3",
"prettier-plugin-curly": "^0.1.3",
"prettier-plugin-packagejson": "^2.4.5",
"release-it": "^16.1.5",
"sentences-per-line": "^0.2.1",
"should-semantic-release": "^0.1.1",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"vitest": "^0.34.5",
"yaml-eslint-parser": "^1.2.2"
},
"peerDependencies": {
"react": "16.x || 17.x || 18.x"
},
"packageManager": "pnpm@8.7.0",
"engines": {
"node": ">=18"
},
"publishConfig": {
"provenance": true
}
}
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