# koa-qs

> qs for koa

Latest version **3.0.0** (published 2020-05-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-qs
pnpm add koa-qs
yarn add koa-qs
bun add koa-qs
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2020-05-27 |
| First published | 2013-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/koa-qs) |
| Module format | CommonJS |
| Node | >= 8 |
| Dependencies | 2 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 89 |
| Author | Jonathan Ong |
| Maintainers | aheckmann, coderhaoxin, dead_horse, dead-horse, eivifj, fengmk2, jongleberry, juliangruber, niftylettuce, tjholowaychuk |

## Links

- npm: https://www.npmjs.com/package/koa-qs
- Repository: https://github.com/koajs/qs
- Homepage: https://github.com/koajs/qs#readme
- Issues: https://github.com/koajs/qs/issues
- npm.io page: https://npm.io/package/koa-qs

## Dependencies (2)

- [qs](https://npm.io/package/qs.md) ^6.9.4
- [merge-descriptors](https://npm.io/package/merge-descriptors.md) ^1.0.1

## Recent versions

- 3.0.0 (latest) — 2020-05-27
- 2.0.0 — 2015-02-28
- 1.1.0 — 2015-02-27
- 1.0.1 — 2014-09-16
- 1.0.0 — 2013-12-19

## README

# Koa Querystring

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![David deps][david-image]][david-url]
[![node version][node-image]][node-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/koa-qs.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-qs
[travis-image]: https://img.shields.io/travis/koajs/qs.svg?style=flat-square
[travis-url]: https://travis-ci.org/koajs/qs
[coveralls-image]: https://img.shields.io/coveralls/koajs/qs.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/koajs/qs?branch=master
[david-image]: https://img.shields.io/david/koajs/qs.svg?style=flat-square
[david-url]: https://david-dm.org/koajs/qs
[node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[download-image]: https://img.shields.io/npm/dm/koa-qs.svg?style=flat-square
[download-url]: https://npmjs.org/package/koa-qs

By default, Koa uses the native `querystring` module which does not provide nesting support.
This patches a koa app with nesting support via the [qs](https://github.com/ljharb/qs) support,
which is also used by Connect and Express.

Simply wrap a koa app with this module:

```js
// Koa 1.x.x
const koa = require('koa')
const app = koa()
require('koa-qs')(app)
// Koa 2.x.x
const Koa = require('koa')
const app = new Koa()
require('koa-qs')(app)
```

## Optional parse mode

There're three parse mode.

## `extended` mode

The default mode, use [qs] module.

```js
require('koa-qs')(app, 'extended')
```

## `simple` mode

Use `querystring` module, same as koa does by default.
If you want to use this mode, don't use this module.

## `strict` mode

This mode make `this.query.foo` return strict `array`.

```js
require('koa-qs')(app, 'strict')
```

#### What's different

A normal request `GET /foo?p=a&q=foo&q=bar`.

- before patch

```js
console.log('%j', this.query);
{
  "p": "a",
  "q": ["foo", "bar"]
}
```

- after patch

```js
console.log('%j', this.query);
{
  "p": ["a"],
  "q": ["foo", "bar"]
}
```

## `first` mode

This mode make `this.query.foo` return strict `string`. Disable multi values.

If querystring contains multi same name params, return the **first** item.

```js
require('koa-qs')(app, 'first')
```

In 95% use cases, application only want `string` query params.

This patch can avoid some stupid `TypeError` and some security issues like [MongoDB inject](http://www.wooyun.org/bugs/wooyun-2010-086474)
when the developers forget handling query params type check.

#### What's different

A normal request `GET /foo?p=a,b&p=b,c`.

- before patch

```js
console.log('%j', this.query.p);
["a,b", "b,c"]
```

- after patch

```js
console.log('%j', this.query.p);
"a,b"
```

## License

[MIT](LICENSE)

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