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.

http-networkingserialization
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

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.

const QS = require('qs-parser');

The `QS` function is used directly as an initializer for a new instance, not as a class constructor with `new`.

QS('http://example.com?foo=bar').get('foo');

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.

QS().get('key');

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 footguns
breakingThis package is currently abandoned. There will be no further updates, bug fixes, or security patches. Users should consider migrating to actively maintained alternatives.
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.
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')`.
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`).
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources