npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@chaisser/query-string

v1.0.0

Published

Parse and stringify query strings with type safety

Downloads

62

Readme

@chaisser/query-string

Parse and stringify query strings with full type safety

Features

  • Type-Safe - Full TypeScript support with exported types for all options and return values
  • Zero Dependencies - No runtime dependencies, lightweight and fast
  • ESM + CJS - Ships both ES Module and CommonJS formats
  • Array Formats - Supports bracket (a[]=1), comma (a=1,2), repeat (a=1&a=2), and none
  • Type Parsing - Automatic number and boolean parsing from query string values
  • URL Encoding/Decoding - Handles URL-encoded values transparently
  • URL Utilities - parseUrl, stringifyUrl, extract, pick, exclude, has, get
  • Flexible Options - Sort keys, skip nulls, skip empty strings, custom encoders

Installation

# npm
npm install @chaisser/query-string

# yarn
yarn add @chaisser/query-string

# pnpm
pnpm add @chaisser/query-string

Quick Start

import { parse, stringify } from '@chaisser/query-string';

// Parse a query string
const params = parse('?name=John&age=30');
// { name: 'John', age: '30' }

// Stringify an object
const qs = stringify({ name: 'John', age: '30' });
// 'name=John&age=30'

What It Does

@chaisser/query-string provides a complete toolkit for working with URL query strings. It handles parsing query strings into typed objects, stringifying objects back into query strings, and includes utilities for working with full URLs.

Usage Examples

Parse

import { parse } from '@chaisser/query-string';

// Basic parsing
parse('foo=bar&baz=qux');
// { foo: 'bar', baz: 'qux' }

// With numbers and booleans
parse('count=5&active=true', { parseNumbers: true, parseBooleans: true });
// { count: 5, active: true }

// Array formats
parse('tags[]=js&tags[]=ts', { arrayFormat: 'bracket' });
// { tags: ['js', 'ts'] }

parse('tags=js,ts', { arrayFormat: 'comma' });
// { tags: ['js', 'ts'] }

parse('tags=js&tags=ts', { arrayFormat: 'repeat' });
// { tags: ['js', 'ts'] }

Stringify

import { stringify } from '@chaisser/query-string';

// Basic
stringify({ foo: 'bar' });
// 'foo=bar'

// Arrays
stringify({ tags: ['js', 'ts'] }, { arrayFormat: 'bracket' });
// 'tags[]=js&tags[]=ts'

stringify({ tags: ['js', 'ts'] }, { arrayFormat: 'comma' });
// 'tags=js,ts'

// Skip null values
stringify({ a: '1', b: null }, { skipNull: true });
// 'a=1'

// Sort keys
stringify({ c: '3', a: '1', b: '2' }, { sort: true });
// 'a=1&b=2&c=3'

parseUrl

import { parseUrl } from '@chaisser/query-string';

parseUrl('https://example.com/path?foo=bar&baz=qux');
// { url: 'https://example.com/path', query: { foo: 'bar', baz: 'qux' } }

stringifyUrl

import { stringifyUrl } from '@chaisser/query-string';

stringifyUrl({ url: 'https://example.com', query: { foo: 'bar' } });
// 'https://example.com?foo=bar'

stringifyUrl({ url: 'https://example.com?existing=yes', query: { new: 'param' } });
// 'https://example.com?existing=yes&new=param'

pick / exclude

import { pick, exclude } from '@chaisser/query-string';

pick('a=1&b=2&c=3', ['a', 'c']);
// 'a=1&c=3'

exclude('a=1&b=2&c=3', ['b']);
// 'a=1&c=3'

has / get

import { has, get } from '@chaisser/query-string';

has('?foo=bar&baz=qux', 'foo');
// true

get('?foo=bar', 'foo');
// 'bar'

get('?foo=bar', 'missing');
// null

API Reference

| Function | Description | |---|---| | parse(queryString, options?) | Parse a query string into a QueryParams object | | stringify(params, options?) | Stringify an object into a query string (no leading ?) | | parseUrl(url, options?) | Parse a URL into { url, query } | | stringifyUrl({ url, query }, options?) | Merge query params into a URL | | extract(url) | Extract the query string portion from a URL | | pick(urlOrQuery, keys, options?) | Keep only specified keys | | exclude(urlOrQuery, keys, options?) | Remove specified keys | | has(urlOrQuery, key) | Check if a key exists | | get(urlOrQuery, key) | Get the value of a key |

ParseOptions

| Option | Type | Default | Description | |---|---|---|---| | arrayFormat | 'bracket' \| 'comma' \| 'repeat' \| 'none' | 'none' | How to parse array values | | parseNumbers | boolean | false | Convert numeric strings to numbers | | parseBooleans | boolean | false | Convert 'true'/'false' to booleans | | decode | boolean | true | URL-decode values |

StringifyOptions

| Option | Type | Default | Description | |---|---|---|---| | arrayFormat | 'bracket' \| 'comma' \| 'repeat' \| 'none' | 'none' | How to format array values | | encode | boolean | true | URL-encode values | | skipNull | boolean | false | Skip keys with null values | | skipEmptyString | boolean | false | Skip keys with empty string values | | sort | boolean \| ((a, b) => number) | false | Sort keys |

Related Packages

License

MIT


Developed by Doruk Karaboncuk ([email protected])

Repository: github.com/Chaisser/query-string