You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-3Lines changed: 48 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Svelte Query Params
2
2
3
-
The easiest way to reactively manage query params in Svelte _and_ SvelteKit applications, both on the server and in the browser. Built on Svelte 5[runes](https://svelte-5-preview.vercel.app/docs/runes) and integrates with existing validation libraries to parse, coerce and transform query params into the data your application needs.
3
+
The easiest way to reactively manage query params in Svelte _and_ SvelteKit applications, both on the server and in the browser. Built for Svelte 5 and integrates with existing validation libraries to parse, coerce and transform query params into the data your application needs.
4
4
5
5
## Installation
6
6
7
-
Since Svelte Query Params uses runes, [`svelte^5`](https://svelte-5-preview.vercel.app/docs/introduction) is required:
7
+
[`svelte^5`](https://svelte-5-preview.vercel.app/docs/introduction) is required:
8
8
9
9
```bash
10
10
npm install svelte-query-params svelte@next
@@ -26,7 +26,7 @@ By default, `svelte-query-params` uses [`URLSearchParams`](https://developer.moz
26
26
27
27
## Features
28
28
29
-
-**Reactivity**: The library leverages Svelte's new runes reactivity system, providing a reactive object that reflects the current state of query parameters.
29
+
-**Reactivity**: The library providies a reactive object that reflects the current state of query parameters.
30
30
31
31
-**Browser and Server Support**: The utility is designed to work seamlessly in both browser and server environments.
32
32
@@ -36,6 +36,10 @@ By default, `svelte-query-params` uses [`URLSearchParams`](https://developer.moz
36
36
37
37
-**Event Handling**: Automatically handles `popstate` events for accurate synchronisation with browser history.
38
38
39
+
-**Serialisation**: Control how query params are serialised into strings to the browser
40
+
41
+
-**Multi-value params**: Supports multi-value query parameters with ease
With a function validator, you may receive the param as either a string, an array of strings, or undefined. As a result, you must handle all three cases to support multi-value params:
151
+
152
+
```javascript
153
+
constvalidators= {
154
+
categories: (value) => {
155
+
if (!value) return []
156
+
returnArray.isArray(value) ? value : [value]
157
+
}
158
+
}
159
+
```
160
+
161
+
With Zod, you need to handle the case where there's either 0 or 1 query param value as this library will not infer this as an array beforehand. You must define your array parameter like:
162
+
163
+
```javascript
164
+
import { z } from"zod";
165
+
166
+
z.object({
167
+
categories: z
168
+
.union([z.string().array(), z.string()])
169
+
.default([])
170
+
.transform((c) => (Array.isArray(c) ? c : [c])),
171
+
})
172
+
```
173
+
174
+
The union between a string and array of strings handles 1 or more query params; a default is set to the empty array to allow the parameter to be omitted from the URL and it's transformed at the end to convert the single value param into an array.
Copy file name to clipboardExpand all lines: packages/core/README.md
+48-3Lines changed: 48 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Svelte Query Params
2
2
3
-
The easiest way to reactively manage query params in Svelte _and_ SvelteKit applications, both on the server and in the browser. Built on Svelte 5[runes](https://svelte-5-preview.vercel.app/docs/runes) and integrates with existing validation libraries to parse, coerce and transform query params into the data your application needs.
3
+
The easiest way to reactively manage query params in Svelte _and_ SvelteKit applications, both on the server and in the browser. Built for Svelte 5 and integrates with existing validation libraries to parse, coerce and transform query params into the data your application needs.
4
4
5
5
## Installation
6
6
7
-
Since Svelte Query Params uses runes, [`svelte^5`](https://svelte-5-preview.vercel.app/docs/introduction) is required:
7
+
[`svelte^5`](https://svelte-5-preview.vercel.app/docs/introduction) is required:
8
8
9
9
```bash
10
10
npm install svelte-query-params svelte@next
@@ -26,7 +26,7 @@ By default, `svelte-query-params` uses [`URLSearchParams`](https://developer.moz
26
26
27
27
## Features
28
28
29
-
-**Reactivity**: The library leverages Svelte's new runes reactivity system, providing a reactive object that reflects the current state of query parameters.
29
+
-**Reactivity**: The library providies a reactive object that reflects the current state of query parameters.
30
30
31
31
-**Browser and Server Support**: The utility is designed to work seamlessly in both browser and server environments.
32
32
@@ -36,6 +36,10 @@ By default, `svelte-query-params` uses [`URLSearchParams`](https://developer.moz
36
36
37
37
-**Event Handling**: Automatically handles `popstate` events for accurate synchronisation with browser history.
38
38
39
+
-**Serialisation**: Control how query params are serialised into strings to the browser
40
+
41
+
-**Multi-value params**: Supports multi-value query parameters with ease
With a function validator, you may receive the param as either a string, an array of strings, or undefined. As a result, you must handle all three cases to support multi-value params:
151
+
152
+
```javascript
153
+
constvalidators= {
154
+
categories: (value) => {
155
+
if (!value) return []
156
+
returnArray.isArray(value) ? value : [value]
157
+
}
158
+
}
159
+
```
160
+
161
+
With Zod, you need to handle the case where there's either 0 or 1 query param value as this library will not infer this as an array beforehand. You must define your array parameter like:
162
+
163
+
```javascript
164
+
import { z } from"zod";
165
+
166
+
z.object({
167
+
categories: z
168
+
.union([z.string().array(), z.string()])
169
+
.default([])
170
+
.transform((c) => (Array.isArray(c) ? c : [c])),
171
+
})
172
+
```
173
+
174
+
The union between a string and array of strings handles 1 or more query params; a default is set to the empty array to allow the parameter to be omitted from the URL and it's transformed at the end to convert the single value param into an array.
0 commit comments