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-parserVerified import paths — ran on the pinned version, not inferred.
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.
Evaluate alternative, actively maintained query string parsing libraries like `query-string` or `qs` (the more popular package by visionmedia).
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.
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.Use `npm install qs-parser --save` for Node.js projects or modern browser bundles. Bower should no longer be used for new projects.
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.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');`.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[]');`.Always provide a URL string argument when initializing `qs-parser` in a Node.js environment: `QS('http://example.com/path?foo=bar')`.No dependency data recorded yet.