# queryzz

> queryzz - a lightweight JS library for manipulating URL query parameters. Get, set, and format queries easily.

Latest version **3.1.5** (published 2024-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install queryzz
pnpm add queryzz
yarn add queryzz
bun add queryzz
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.5 |
| Published | 2024-10-14 |
| First published | 2021-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 19.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Valerii Strilets |
| Maintainers | letstri |
| Keywords | queryzz, query, set, get, format, getQuery, formatQuery, setQuery, typescript, react, vue, useQuery |

## Links

- npm: https://www.npmjs.com/package/queryzz
- Repository: https://github.com/letstri/queryzz
- Homepage: https://github.com/letstri/queryzz#readme
- Issues: https://github.com/letstri/queryzz/issues
- npm.io page: https://npm.io/package/queryzz

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 3.1.5 (latest) — 2024-10-14
- 3.1.4 — 2024-10-13
- 3.1.3 — 2024-10-13
- 3.1.2 — 2024-10-13
- 3.1.1 — 2024-10-13
- 3.1.0 — 2024-10-13
- 3.0.4 — 2024-10-13
- 3.0.3 — 2024-10-13
- 3.0.2 — 2024-10-13
- 3.0.1 — 2024-10-13
- 3.0.0 — 2024-10-13
- 2.0.0 — 2023-09-14
- 1.0.3 — 2022-04-20
- 1.0.2 — 2022-04-19
- 1.0.1 — 2022-04-19
- … 1 more at https://npm.io/package/queryzz/versions

## README

# queryzz.js

> queryzz - a lightweight JS library for manipulating URL query parameters. Get, set, and format queries easily.

[![npm version](https://badge.fury.io/js/queryzz.svg)](https://www.npmjs.com/package/queryzz)
[![](https://data.jsdelivr.com/v1/package/npm/queryzz/badge)](https://www.jsdelivr.com/package/npm/queryzz)

## Quick start

### Install

```shell
npm i queryzz
```

## Usage

```js
import { getQuery } from 'queryzz'

getQuery()
```

## Methods

### formatQuery

Format query string from an object.

```js
const query = { value: 'test', field: ['hi', 'hello'] }

formatQuery(query)
// => value=test&field=hi&field=hello
```

```js
const query = { value: 'https://google.com' }

formatQuery(query, true)
// => value=https%3A%2F%2Fgoogle.com
```

```js
const query = { value: 'https://google.com' }

formatQuery(query, false)
// => value=https://google.com
```

* * *

### getQuery

Get query from an url.

```js
// URL: /?value=test&field=hi&field=hello

getQuery()
// => { value: 'test', field: ['hi', 'hello'] }
```

```js
getQuery('value=test&field=hi&field=hello')

// => { value: 'test', field: ['hi', 'hello'] }
```

```js
// URL: /?value=test&field=hi

getQuery({ arrays: ['value'] })

// => { value: ['test'], field: 'hi' }
```

```js
// URL: /?value=test&field=hi&value=123&test=true

getQuery()

// => { value: ['test', 123], field: 'hi', test: true }
```

```js
getQuery({
  source: 'value=test&field=hi&value=123&test=true',
  parse: false
})

// => { value: ['test', '123'], field: 'hi', test: 'true' }
```

* * *

### setQuery

Set query to the url.

```js
setQuery({ test: 'value' })

// => URL: /?test=value
```

```js
setQuery({ test: ['12', '34'] })

// => URL: /?test=12&test=34
```

```js
// /?test=value&field=test

setQuery({ test: 'field' }, { saveOld: true })

// => URL: /?test=value&test=field&field=test
```

```js
// URL: /?test=value#someHash

setQuery({ test: 'value' }, { saveHash: false })

// => URL: /?test=value
```

## React

### useQuery

```js
const [search, setSearch] = useQuery('search')

setSearch('test')

// => URL: /?search=test
```

```js
// URL: /?search=test

const [search, setSearch] = useQuery('search', { array: true })

console.log(search)
// => ['test']

setSearch(['test', 'test2'])

// => URL: /?search=test&search=test2
```

```js
// URL: /?page=1

const [page, setPage] = useQuery('page', { parse: false })

console.log(page)
// => '1'
```

## Vue

### useQuery

```js
const search = useQuery('search')

search.value = 'test'

// => URL: /?search=test
```

```js
// URL: /?search=test

const search = useQuery('search', { array: true })

console.log(search.value)
// => ['test']

search.value = ['test', 'test2']

// => URL: /?search=test&search=test2
```

```js
// URL: /?page=1

const page = useQuery('page', { parse: false })

console.log(page.value)
// => '1'
```

## Author

© [letstri](https://letstri.dev), released under the [MIT](https://github.com/letstri/queryzz/blob/main/LICENSE) license.

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