Registry / http-networking / qs-parser

qs-parser

JSON →
library0.4.8jsnpmunverified

The `qs-parser` package, often referred to as `QS`, provides a lightweight utility for parsing, manipulating, and reconstructing URL query strings. It enables developers to easily extract individual query parameters, retrieve all parameters as an object, and verify the existence of specific keys. The library supports dynamic modification of query strings by adding new tokens, updating existing values, or completely removing parameters. A distinctive feature is its `go()` method, which can directly navigate the browser to the newly constructed URL. It handles URL encoding/decoding automatically and performs type conversion for numbers and arrays, with array parameters requiring a `[]` suffix in their key names. The current stable version is `0.4.8`. Given the inactivity in its GitHub repository, the project appears to be abandoned, meaning there are no active developments or a defined release cadence.

npm install qs-parser
INSTALL
IMPORT
SIG · QS-PARSER
Q
qs-parser
http-networkingjavascriptv0.4.8
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

QS
✓ const QS = require('qs-parser');
✗ import QS from 'qs-parser';
This package is primarily designed for CommonJS environments. For ESM, a bundler or `import * as QS from 'qs-parser';` might be required for interoperability. The default import style shown as 'wrong' is common for ESM modules, but this package exposes its API via CommonJS module.exports.
QS
✓ QS('http://example.com?foo=bar').get('foo');
✗ new QS('http://example.com?foo=bar').get('foo');
The `QS` function is used directly as an initializer for a new instance, not as a class constructor with `new`.
QS
✓ QS().get('key');
✗ const QS_Instance = QS; QS_Instance().get('key');
When called without arguments in a browser environment, `QS()` automatically parses `window.location.search`. This behavior is not supported in Node.js where a URL string must always be provided.

This example demonstrates how to initialize `qs-parser` with a URL, perform various read operations to retrieve parameters and check their existence, and then chain multiple write operations (set, add, remove) to modify the query string. It also shows the updated `url` property on the `qs` instance.

const QS = require('qs-parser'); // Example URL for demonstration const currentUrl = 'http://www.somedomain.com/somepage?foo=bar&email=nire0510%40gmail.com&number=345.678&cars%5B%5D=BMW&cars%5B%5D=Audi'; // Initialize QS parser with a specific URL const qs = QS(currentUrl); console.log('--- Read Operations ---'); console.log('Original URL:', qs.url); console.log('Value of "foo":', qs.get('foo')); // Expected: 'bar' console.log('Value of "email":', qs.get('email')); // Expected: 'nire0510@gmail.com' console.log('Value of "number":', qs.get('number')); // Expected: 345.678 console.log('Value of "cars[]":', qs.get('cars[]')); // Expected: ['BMW', 'Audi'] console.log('All tokens:', qs.getAll()); // Expected: { foo: 'bar', email: 'nire0510@gmail.com', number: 345.678, 'cars[]': [ 'BMW', 'Audi' ] } console.log('Does "foo" exist?', qs.has('foo')); // Expected: true console.log('\n--- Write Operations (Chainable) ---'); qs.set('foo', 'newBar') // Change existing value .set('dal', 'mon') // Add a new token .remove('number'); // Remove a token console.log('Modified URL property (before .go()):', qs.url); // Expected URL to resemble: "http://www.somedomain.com/somepage?foo=newBar&email=nire0510%40gmail.com&cars%5B%5D=BMW&cars%5B%5D=Audi&dal=mon" // In a browser, calling .go() would navigate to the new URL. // For this runnable example, we'll avoid actual navigation. // console.log('\nNavigating (if .go() was called):', qs.go());
Debug
Known issues
breakingThis package is currently abandoned. There will be no further updates, bug fixes, or security patches. Users should consider migrating to actively maintained alternatives.
fix
Evaluate alternative, actively maintained query string parsing libraries like `query-string` or `qs` (the more popular package by visionmedia).
affects: >=0.4.8
gotchaThe `.go()` method directly navigates the browser to the modified URL. This can cause unintended page reloads if not used carefully, especially in single-page applications where route changes are typically handled by client-side routers.
fix
Avoid using `.go()` in environments where direct page navigation is undesirable. Instead, retrieve the modified URL from the `.url` property and integrate it with your application's routing mechanism if needed.
affects: >=0.1.0
gotchaFor parsing arrays from the query string, parameters must be explicitly suffixed with `[]` (e.g., `cars[]=BMW&cars[]=Audi`). If `cars=BMW&cars=Audi` is used, only the last value ('Audi') will be returned by `get('cars')`.
fix
Ensure that array parameters in your URLs are formatted with the `[]` suffix (e.g., `key[]=value1&key[]=value2`) and use the same `get('key[]')` method to retrieve them.
affects: >=0.1.0
deprecatedThe README suggests installation via Bower (`bower install qs --save`), which is a deprecated package manager. npm is the recommended modern approach (`npm install qs-parser --save`).
fix
Use `npm install qs-parser --save` for Node.js projects or modern browser bundles. Bower should no longer be used for new projects.
affects: <=0.4.8
Errors
Common errors & fixes
ReferenceError: QS is not defined
The library was not correctly imported or included in the project scope, or it's an ESM import attempting to use CJS-style module.
fix
For CommonJS, ensure `const QS = require('qs-parser');` is at the top of your file. For browser environments, verify the `<script src="..."></script>` tag is correctly placed and loaded.
TypeError: QS(...).get is not a function
Attempting to call methods on the `QS` function itself rather than an instance returned by calling `QS` with a URL.
fix
Call `QS` with a URL string (or without for `window.location` in a browser) to get an instance, then call methods on that instance: `QS('http://your-url.com').get('key');`.
Incorrect parsing of array parameters (only last value returned for `key=val1&key=val2`)
The library expects array query parameters to be explicitly suffixed with `[]` (e.g., `key[]=val1&key[]=val2`). Without this, it treats repeated keys as overwrites.
fix
Format your array parameters as `key[]=value` in the URL and retrieve them using `qs.get('key[]')`. For example, `QS('?items[]=a&items[]=b').get('items[]');`.
ReferenceError: window is not defined (in Node.js environment)
Calling `QS()` without any arguments in a Node.js environment. This attempts to parse `window.location.search`, which is a browser-specific global object.
fix
Always provide a URL string argument when initializing `qs-parser` in a Node.js environment: `QS('http://example.com/path?foo=bar')`.
Upgrade
Version history
0.4.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
qs-parser — npm install qs-parser · libregistry