explaingit

sindresorhus/query-string

Analysis updated 2026-06-24

6,903JavaScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A JavaScript library for parsing URL query strings into objects and stringifying objects back into query strings, with fine-grained control over list encoding, type coercion, and key sorting.

Mindmap

mindmap
  root((query-string))
    What it does
      Parse query strings
      Stringify objects
    Key features
      List encoding options
      Type coercion
      Key sorting
    Environments
      Browser
      Node.js
    Use cases
      URL manipulation
      Filter state sync
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Parse a URL query string into a JavaScript object with automatic number and boolean type conversion

USE CASE 2

Build a query string from an object using comma-separated or bracket-notation list encoding

USE CASE 3

Replace the browser native URLSearchParams when you need stricter control over encoding formats

USE CASE 4

Declare per-field types so parsed values always come back as the right data type without manual casting

What is it built with?

JavaScriptNode.js

How does it compare?

sindresorhus/query-stringai/size-limitveltman/flubber
Stars6,9036,9066,907
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasyeasyeasy
Complexity2/52/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min
Open-source license, use freely in personal and commercial projects.

In plain English

query-string is a small JavaScript library for reading and writing the part of a URL that comes after the question mark. That part is called a query string, and it carries data like search terms or filter settings. For example, a URL like "example.com/search?term=cat&page=2" has a query string of "term=cat&page=2". The library provides two main operations. Parsing takes a raw query string and converts it into a plain JavaScript object, so each key-value pair becomes a property you can work with in code. Stringifying does the reverse: it takes an object and produces a properly formatted query string you can attach to a URL. Beyond the basics, the library handles several tricky situations that the browser's built-in alternative does not cover as completely. You can control how lists of values are encoded and decoded, choosing between several formats such as repeated keys, comma-separated values, or bracket notation. There are options to automatically convert values to numbers or booleans instead of leaving everything as a string, and a "types" option lets you declare exactly what type each field should have. Sorting of keys can be customized or disabled. The package is installed via npm and works in both browser and server-side JavaScript environments. The README suggests the browser's native URLSearchParams API for simple cases, and positions this library for situations where finer control is needed. The code and model are both under open-source licenses. The repository is maintained by Sindre Sorhus, a prolific open-source author.

Copy-paste prompts

Prompt 1
Using the query-string npm package, write a function that parses this URL and returns a typed object: 'https://example.com/search?tags[]=cats&tags[]=dogs&page=2&active=true'
Prompt 2
With query-string, convert this JavaScript object to a URL query string using comma-separated arrays: { colors: ['red', 'blue'], limit: 10, active: true }
Prompt 3
Show me how to use query-string to read the current page URL params, update a single key, and write the new query string back to the URL bar without reloading.
Prompt 4
In query-string, how do I parse a query string so numeric values are numbers, booleans are booleans, and arrays use bracket notation?

Frequently asked questions

What is query-string?

A JavaScript library for parsing URL query strings into objects and stringifying objects back into query strings, with fine-grained control over list encoding, type coercion, and key sorting.

What language is query-string written in?

Mainly JavaScript. The stack also includes JavaScript, Node.js.

What license does query-string use?

Open-source license, use freely in personal and commercial projects.

How hard is query-string to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is query-string for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.