svelte-qparam

npm-version npm-license npm-download-month npm-min-size ci.yml website

🔎 Type-Safe Query Parameter for SvelteKit

â–· Installation

https://svelte-qparam.jill64.dev/?

str = num = 0 bool_array = []
<!-- +page.svelte -->
<script>
  import { page } from '$app/state'
  import { array, define } from 'svelte-qparam'
  import { boolean, number, string } from 'typed-qparam/serde'

  const qparam = define({
    str: string,
    num: number,
    bool_array: array(boolean)
  })

  let { qparams: q } = $derived(qparam(page.url))
</script>

<div>
  <button
    onclick={() => {
      q.str = 'Hello, World!'
    }}
  >
    Set str = Hello, World!
  </button>
</div>
<output>
  <code>str = {q.str}</code>
  <code>num = {q.num}</code>
  <code>bool_array = {JSON.stringify(q.bool_array)}</code>
</output>