# @1k/qs

> Lightweight query string parsing and stringify library

Latest version **0.0.3** (published 2026-11-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @1k/qs
pnpm add @1k/qs
yarn add @1k/qs
bun add @1k/qs
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2026-11-28 |
| First published | 2025-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^26.0.0 |
| Dependencies | 1 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | scriptpower |
| Maintainers | scriptpower |
| Keywords | query string, querystring, qs, parse, stringify, lightweight |

## Links

- npm: https://www.npmjs.com/package/@1k/qs
- npm.io page: https://npm.io/package/@1k/qs

## Dependencies (1)

- [es-fns](https://npm.io/package/es-fns.md) 0.0.3

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2026-11-28
- 0.0.2 — 2025-03-13

## README

# @1k/qs

Lightweight query string parse and stringify utilities with protection
against prototype pollution and malformed URI sequences.

If you only need to read query parameters in a browser environment,
consider the built-in [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) first.

## Installation

```bash
npm install --save @1k/qs
```

## Usage

```js
import { parse, stringify } from '@1k/qs'
```

### parse()

Parses a query string into a key-value object.

Parameters without values are set to empty strings.
The leading `?`, `#`, or no prefix are all handled transparently.

```js
parse('foo=bar')          // { foo: 'bar' }
parse('?foo=bar')         // { foo: 'bar' }
parse('#foo=bar')         // { foo: 'bar' }
parse('foo=bar&bar=foo')  // { foo: 'bar', bar: 'foo' }
parse('foo&bar=foo')      // { foo: '', bar: 'foo' }
```

#### Duplicate keys

By default, duplicate keys are merged into arrays:

```js
parse('a=1&a=2&a=3')  // { a: ['1', '2', '3'] }
```

Use `{ onlyFirst: true }` to get the first value as a plain string instead:

```js
parse('a=1&a=2&a=3', { onlyFirst: true })  // { a: '1' }
```

#### Decoding

`+` is decoded as space (per `application/x-www-form-urlencoded`):

```js
parse('key=a+b')  // { key: 'a b' }
```

Percent-encoded values are decoded via `decodeURIComponent`:

```js
parse('key=%E4%B8%AD%E6%96%87')  // { key: '中文' }
```

Malformed URI sequences (e.g. `%E`) are returned as-is without throwing:

```js
parse('key=%E&val=%GG')  // { key: '%E', val: '%GG' }
```

#### Custom decode

```js
parse('key=hello', { decode: (s) => s.toUpperCase() })
// { key: 'HELLO' }
```

#### Prototype pollution protection

The returned object has no prototype chain (`Object.create(null)`),
so keys like `__proto__` or `toString` won't pollute global objects.

```js
parse('__proto__[polluted]=true')  // safe — no prototype
```

### stringify()

Serializes an object into a URL-encoded query string.

```js
stringify({ foo: 'bar' })            // 'foo=bar'
stringify({ foo: 'bar', baz: 'qux' }) // 'foo=bar&baz=qux'
```

#### Prefix

Pass `true` or a custom string to add a prefix:

```js
stringify({ foo: 'bar' }, true)  // '?foo=bar'
stringify({ foo: 'bar' }, '#')   // '#foo=bar'
stringify({ foo: 'bar' }, '&')   // '&foo=bar'
```

#### Edge cases

```js
stringify({ a: null, b: NaN })        // 'a=&b='
stringify({ a: undefined })           // ''
stringify({})                          // ''
```

## License

MIT

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