Skip to content

Commit 35179e9

Browse files
committed
fix: types
1 parent 9fafe28 commit 35179e9

22 files changed

Lines changed: 895 additions & 113 deletions

eslint.config.mjs

Lines changed: 0 additions & 15 deletions
This file was deleted.

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nuxt-cart",
3-
"version": "0.1.1",
3+
"version": "1.0.0",
44
"description": "A generic, reusable shopping cart module for Nuxt 4 with localStorage persistence, coupon support, and optional Nuxt UI components",
55
"author": "rrd <rrd@webmania.cc>",
66
"license": "MIT",
@@ -46,11 +46,11 @@
4646
"dev": "nuxi dev playground",
4747
"dev:build": "nuxi build playground",
4848
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
49-
"lint": "eslint .",
50-
"lint:fix": "eslint . --fix",
49+
"lint": "oxlint --deny-warnings",
50+
"lint:fix": "oxlint --fix --deny-warnings",
5151
"test": "vitest run",
5252
"test:watch": "vitest watch",
53-
"test:types": "vue-tsc --noEmit",
53+
"test:types": "cd playground && vue-tsc --noEmit",
5454
"docs:dev": "vitepress dev docs",
5555
"docs:build": "vitepress build docs",
5656
"docs:preview": "vitepress preview docs",
@@ -76,6 +76,7 @@
7676
"changelogen": "^0.6.2",
7777
"dotenv-cli": "^11.0.0",
7878
"nuxt": "^4.0.0",
79+
"oxlint": "^1.69.0",
7980
"pinia": "^3.0.0",
8081
"typescript": "~5.8.3",
8182
"vitepress": "^1.6.4",
@@ -89,7 +90,9 @@
8990
"pinia": "^3.0.0"
9091
},
9192
"pnpm": {
92-
"onlyBuiltDependencies": ["better-sqlite3"]
93+
"onlyBuiltDependencies": [
94+
"better-sqlite3"
95+
]
9396
},
9497
"peerDependenciesMeta": {
9598
"@nuxt/ui": {

playground/layouts/default.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
defineOptions({ name: 'PlaygroundDefault' })
3+
24
const cart = useCart()
35
const drawerOpen = ref(false)
46
const router = useRouter()
@@ -9,7 +11,10 @@ const router = useRouter()
911
<div class="min-h-screen bg-background">
1012
<header class="sticky top-0 z-50 border-b bg-background/80 backdrop-blur-sm">
1113
<div class="mx-auto flex max-w-5xl items-center justify-between px-4 py-3">
12-
<NuxtLink to="/" class="text-lg font-bold hover:text-primary">
14+
<NuxtLink
15+
to="/"
16+
class="text-lg font-bold hover:text-primary"
17+
>
1318
Nuxt Cart
1419
</NuxtLink>
1520
<div class="flex items-center gap-2">

playground/nuxt.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export default defineNuxtConfig({
44
'@nuxt/ui',
55
],
66

7+
devtools: { enabled: true },
8+
79
nuxtCart: {
810
persist: true,
911
apiRoutes: true,
@@ -14,6 +16,4 @@ export default defineNuxtConfig({
1416
options: { path: './.data/cart.sqlite3' },
1517
},
1618
},
17-
18-
devtools: { enabled: true },
1919
})

playground/pages/cart.vue

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
defineOptions({ name: 'PlaygroundCart' })
23
definePageMeta({
34
title: 'Shopping Cart',
45
})
@@ -40,7 +41,10 @@ function removeItem(productId: string) {
4041
Shopping Cart
4142
</h1>
4243

43-
<div v-if="cart.isEmpty.value" class="flex flex-col items-center gap-4 py-16 text-center">
44+
<div
45+
v-if="cart.isEmpty.value"
46+
class="flex flex-col items-center gap-4 py-16 text-center"
47+
>
4448
<span class="i-lucide-shopping-cart text-6xl text-muted" />
4549
<p class="text-lg text-muted">
4650
Your cart is empty
@@ -50,7 +54,10 @@ function removeItem(productId: string) {
5054
</UButton>
5155
</div>
5256

53-
<div v-else class="grid gap-8 lg:grid-cols-3">
57+
<div
58+
v-else
59+
class="grid gap-8 lg:grid-cols-3"
60+
>
5461
<div class="space-y-3 lg:col-span-2">
5562
<UCard
5663
v-for="item in cart.items.value"
@@ -63,7 +70,7 @@ function removeItem(productId: string) {
6370
:src="item.image"
6471
:alt="item.name"
6572
class="h-20 w-20 flex-shrink-0 rounded-lg object-cover"
66-
/>
73+
>
6774
<div class="min-w-0 flex-1">
6875
<p class="font-medium truncate">
6976
{{ item.name }}
@@ -103,7 +110,12 @@ function removeItem(productId: string) {
103110
</div>
104111
</UCard>
105112

106-
<UButton variant="soft" color="error" size="sm" @click="cart.clear()">
113+
<UButton
114+
variant="soft"
115+
color="error"
116+
size="sm"
117+
@click="cart.clear()"
118+
>
107119
Clear Cart
108120
</UButton>
109121
</div>
@@ -122,12 +134,15 @@ function removeItem(productId: string) {
122134
<span>${{ cart.totalAmount.value.toFixed(2) }}</span>
123135
</div>
124136

125-
<div v-if="cart.coupon.value" class="flex items-center justify-between text-green-600">
137+
<div
138+
v-if="cart.coupon.value"
139+
class="flex items-center justify-between text-green-600"
140+
>
126141
<div class="flex items-center gap-1">
127142
<span>Discount ({{ cart.coupon.value.code }})</span>
128143
<UButton
129144
icon="i-lucide-x"
130-
size="2xs"
145+
size="xs"
131146
color="error"
132147
variant="ghost"
133148
@click="removeCoupon"
@@ -136,15 +151,22 @@ function removeItem(productId: string) {
136151
<span>- ${{ (cart.totalAmount.value - cart.discountedTotal.value).toFixed(2) }}</span>
137152
</div>
138153

139-
<div v-if="cart.coupons && !cart.coupon.value" class="flex gap-2">
154+
<div
155+
v-if="!cart.coupon.value"
156+
class="flex gap-2"
157+
>
140158
<UInput
141159
v-model="couponCode"
142160
placeholder="Coupon code"
143161
size="sm"
144162
class="flex-1"
145163
@keydown.enter="applyCoupon"
146164
/>
147-
<UButton size="sm" variant="soft" @click="applyCoupon">
165+
<UButton
166+
size="sm"
167+
variant="soft"
168+
@click="applyCoupon"
169+
>
148170
Apply
149171
</UButton>
150172
</div>

playground/pages/checkout.vue

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
defineOptions({ name: 'PlaygroundCheckout' })
23
definePageMeta({
34
title: 'Checkout',
45
})
@@ -51,13 +52,19 @@ async function placeOrder() {
5152
:src="item.image"
5253
:alt="item.name"
5354
class="h-12 w-12 rounded-lg object-cover"
54-
/>
55+
>
5556
<div>
56-
<p class="font-medium">{{ item.name }}</p>
57-
<p class="text-sm text-muted">Qty: {{ item.quantity }}</p>
57+
<p class="font-medium">
58+
{{ item.name }}
59+
</p>
60+
<p class="text-sm text-muted">
61+
Qty: {{ item.quantity }}
62+
</p>
5863
</div>
5964
</div>
60-
<p class="font-medium">${{ (item.price * item.quantity).toFixed(2) }}</p>
65+
<p class="font-medium">
66+
${{ (item.price * item.quantity).toFixed(2) }}
67+
</p>
6168
</div>
6269
</div>
6370

@@ -68,7 +75,10 @@ async function placeOrder() {
6875
<span>Subtotal</span>
6976
<span>${{ cart.totalAmount.value.toFixed(2) }}</span>
7077
</div>
71-
<div v-if="cart.coupon.value" class="flex justify-between text-green-600">
78+
<div
79+
v-if="cart.coupon.value"
80+
class="flex justify-between text-green-600"
81+
>
7282
<span>Discount ({{ cart.coupon.value.code }})</span>
7383
<span>- ${{ (cart.totalAmount.value - cart.discountedTotal.value).toFixed(2) }}</span>
7484
</div>
@@ -80,7 +90,10 @@ async function placeOrder() {
8090
</UCard>
8191

8292
<div class="flex gap-3">
83-
<UButton variant="soft" @click="router.back()">
93+
<UButton
94+
variant="soft"
95+
@click="router.back()"
96+
>
8497
Back
8598
</UButton>
8699
<UButton

playground/pages/index.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
defineOptions({ name: 'PlaygroundIndex' })
3+
24
const cart = useCart()
35
const toast = useToast()
46
@@ -32,7 +34,7 @@ const categories = [
3234
]
3335
3436
cart.onValidateCoupon(async (code) => {
35-
const coupons: Record<string, { discount: number; type: 'percentage' | 'fixed' }> = {
37+
const coupons: Record<string, { discount: number, type: 'percentage' | 'fixed' }> = {
3638
SAVE10: { discount: 10, type: 'percentage' },
3739
FLAT5: { discount: 5, type: 'fixed' },
3840
WELCOME20: { discount: 20, type: 'percentage' },
@@ -41,7 +43,7 @@ cart.onValidateCoupon(async (code) => {
4143
return c ? { code: code.toUpperCase(), ...c } : null
4244
})
4345
44-
function addToCart(product: { productId: string; name: string; price: number; image?: string }) {
46+
function addToCart(product: { productId: string, name: string, price: number, image?: string }) {
4547
cart.addItem(product)
4648
toast.add({
4749
title: 'Added to cart',
@@ -63,7 +65,11 @@ function addToCart(product: { productId: string; name: string; price: number; im
6365
</p>
6466
</section>
6567

66-
<section v-for="cat in categories" :key="cat.name" class="space-y-4">
68+
<section
69+
v-for="cat in categories"
70+
:key="cat.name"
71+
class="space-y-4"
72+
>
6773
<div class="flex items-center gap-2">
6874
<span :class="[cat.icon, 'h-5 w-5 text-primary']" />
6975
<h2 class="text-xl font-semibold">
@@ -82,7 +88,7 @@ function addToCart(product: { productId: string; name: string; price: number; im
8288
:alt="product.name"
8389
class="h-48 w-full object-cover"
8490
loading="lazy"
85-
/>
91+
>
8692
<div class="space-y-2 p-4">
8793
<h3 class="font-semibold">
8894
{{ product.name }}

0 commit comments

Comments
 (0)