// extract.js
import { array, define } from 'svelte-qparam'
import { boolean, number, string } from 'svelte-qparam/serde'
export const extract = define({
str: string,
num: number,
bool_array: array(boolean)
})
// +page.server.js
import { extract } from 'extract.js'
export const load = ({ url }) => {
const { values } = extract(url)
/* {
str: string;
num: number;
bool_array: boolean[];
} */
console.log(values)
return {
values
// Note: Cannot return `qparams` from server
// ...
}
}
<!-- +page.svelte -->
<script>
export let data
$: ({ values } = data)
$: ({ str, num, bool_array } = values)
</script>
<output>
<code>server_str = {str}</code>
<code>server_num = {num}</code>
<code>server_bool_array = {JSON.stringify(bool_array)}</code>
</output>