# typed-qparam

> 🔍 Type-safe query parameter manipulation

Latest version **2.1.15** (published 2025-03-14) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install typed-qparam
pnpm add typed-qparam
yarn add typed-qparam
bun add typed-qparam
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.1.15 |
| Published | 2025-03-14 |
| First published | 2023-10-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jill64 |
| Maintainers | jill64 |
| Keywords | library, querystring, typesafe |

## Links

- npm: https://www.npmjs.com/package/typed-qparam
- Repository: https://github.com/jill64/typed-qparam
- Homepage: https://github.com/jill64/typed-qparam#readme
- Issues: https://github.com/jill64/typed-qparam/issues
- npm.io page: https://npm.io/package/typed-qparam

## Dependencies (1)

- [ts-serde](https://npm.io/package/ts-serde.md) 1.0.9

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 2.1.15 (latest) — 2025-03-14
- 2.1.14 — 2025-03-07
- 2.1.13 — 2024-09-26
- 2.1.12 — 2024-07-10
- 2.1.11 — 2024-07-10
- 2.1.10 — 2024-04-20
- 2.1.9 — 2024-04-19
- 2.1.8 — 2024-04-10
- 2.1.7 — 2024-04-10
- 2.1.6 — 2024-02-17
- 2.1.5 — 2024-02-16
- 2.1.4 — 2023-12-19
- 2.1.3 — 2023-12-19
- 2.1.2 — 2023-12-06
- 2.1.1 — 2023-12-05
- … 12 more at https://npm.io/package/typed-qparam/versions

## README

<!----- BEGIN GHOST DOCS HEADER ----->

# typed-qparam

<!----- BEGIN GHOST DOCS BADGES ----->

<a href="https://npmjs.com/package/typed-qparam"><img src="https://img.shields.io/npm/v/typed-qparam" alt="npm-version" /></a> <a href="https://npmjs.com/package/typed-qparam"><img src="https://img.shields.io/npm/l/typed-qparam" alt="npm-license" /></a> <a href="https://npmjs.com/package/typed-qparam"><img src="https://img.shields.io/npm/dm/typed-qparam" alt="npm-download-month" /></a> <a href="https://npmjs.com/package/typed-qparam"><img src="https://img.shields.io/bundlephobia/min/typed-qparam" alt="npm-min-size" /></a> <a href="https://github.com/jill64/typed-qparam/actions/workflows/ci.yml"><img src="https://github.com/jill64/typed-qparam/actions/workflows/ci.yml/badge.svg" alt="ci.yml" /></a>

<!----- END GHOST DOCS BADGES ----->

🔍 Type-safe query parameter manipulation

<!----- END GHOST DOCS HEADER ----->

> [!NOTE]
> See [here](./docs/v1.md) for documentation on <=v1 features.

## Installation

```sh
npm i typed-qparam
```

## Simple Usage

Passing a query parameter key to the `qparam` function returns the accessor for that value.

```js
import { extract } from 'typed-qparam'

const qparam = extract(new URL('https://example.com/?foo=bar'))

const foo = qparam('foo')

// output: 'bar'
console.log(foo.get())

// .set() only returns a new URL instance.
// The original URL instance is not changed.
// No navigation of any kind will occur.

// url: new URL('https://example.com/?foo=baz')
const url = foo.set('baz')

// output: 'https://example.com/?foo=baz'
console.log(url.href)
```

## Typed Param

By passing a conversion function as the second argument, you can obtain a value converted to any type.
See [ts-serde](https://github.com/jill64/ts-serde#readme) for more information on type guard.

```js
import { extract } from 'typed-qparam'
import { number } from 'typed-qparam/serde'

const qparam = extract(new URL('https://example.com/?num=123'))

const num = qparam('num', {
  stringify: (value) => value.toString(),
  parse: (str) => parseInt(str)
})

// output 123
console.log(num.get())

// https://example.com/?key=456
const dist = num.set(456)
```

### Prepared Converter

You can also use the prepared converters in `typed-qparam/serde`.
See [ts-serde](https://github.com/jill64/ts-serde#readme) for more information on type guard

```js
import { extract } from 'typed-qparam'
import { number, boolean, enums } from 'typed-qparam/serde'

const qparam = extract(
  new URL('https://example.com/?num=123&bool=true&enumerate=b')
)

const num = qparam('num', number)
const bool = qparam('bool', boolean)
const enumerate = qparam(
  'enumerate',
  enums(
    ['a', 'b', 'c'],
    'a' // fallback default value
  )
)
```

## Array Param

Sometimes you need to handle query parameters with multiple values in the same key, such as `?str=hello&str=world`.  
With `typed-qparam`, you can treat this as an array.

```js
import { extract, array } from 'svelte-qparam'
import { string, number } from 'svelte-qparam/serde'

const qparam = extract(new URL('https://example.com/?str=hello&str=world'))

const str = qparam('str', array())
// is equivalent to
// const str = qparam('str', array(string))

// if require other typed value
const num = qparam('num', array(number))

// output ['hello', 'world']
console.log(str.get())

// https://example.com/?str=foo&str=bar&str=baz
str.set(['foo', 'bar', 'baz'])
```

<!----- BEGIN GHOST DOCS FOOTER ----->

## License

[MIT](LICENSE)

<!----- END GHOST DOCS FOOTER ----->

---
_Source: https://npm.io/package/typed-qparam · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
