Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@deckweiss/cart

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@deckweiss/cart

This is a shopping cart implementation for SvelteKit applications at Deckweiss.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
0
Weekly downloads
 
Created
Source

Cart for SvelteKit

This is a shopping cart implementation for SvelteKit applications at Deckweiss.

Installation

Step 1: Install package

pnpm i @deckweiss/cart

Step 2: Initialize cart

// src/hooks.client.ts
import { initializeClientCart } from '@deckweiss/cart'

initializeClientCart()
// src/hooks.server.ts
import { handle } from '@deckweiss/cart'

export { handle }

Step 3: Use cart

<script lang="ts">
import { cart, addOrAppendToProduct, removeProduct, clearCart } from '@deckweiss/cart'
</script>

<button on:click={() => addOrAppendToProduct('id1', 1)}>Add product 1</button>
<button on:click={() => addOrAppendToProduct('id2', 1)}>Add product 2</button>
<button on:click={clearCart}>Clear cart</button>

{#each $cart.products as product}
    <div>
        <h3>{product.id}</h3>
        <p>Amount: {product.amount}</p>
        <button on:click={() => removeProduct(product.id)}>Remove product</button>
    </div>
{:else}
    <p>Cart is empty</p>
{/each}

Custom metadata with TypeScript

The types CartMetaData and CartProductMetaData support to be extended/augmented via TypeScript. This means, your editor will recognize the custom types and give you intellisense.

// src/app.d.ts
declare module '@deckweiss/cart' {
    interface CartMetaData {
        userId?: string
	note?: string
	discountCode?: string
    }

    interface CartProductMetaData {
        type?: 'food''tool' | 'book'
    }
}

FAQs

Package last updated on 27 Jul 2024

Did you know?

Socket

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.

Install

Related posts

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