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 🙏

© 2024 – Pkg Stats / Ryan Hefner

qs-parser

v0.4.8

Published

Simple query string tokens parser

Downloads

88

Readme

QS - Simple query string tokens parser

QS helps you extract & manipulate all query string tokens from a given or current valid url: you can check if a specific query string key exists, then check its value. You can also manipulate query string tokens by adding new ones, change values of existing tokens or removing them completely. After manipulation is done, just call go() to navigate to the modified URL.

Installation:

  • Install via bower: bower install qs --save
    Then add qs.min.js file to your website:
    <script src="bower_components/qs/dist/qs.min.js"></script>

  • Install via npm: npm install qs-parser --save
    Then add reference to library:
    const QS = require('qs-parser');

Code samples:

Read

// Get **foo** query string decoded value from a given url:
QS('http://www.somedomain.com/somepage?foo=bar').get('foo');
// => 'bar'

// You may specify a default value in case query string is missing or empty:
QS('http://www.somedomain.com/somepage?bar=baz').get('foo', 'hello');
// => 'hello'

// Notice that URL should contain only valid characters, which means query string tokens should be encoded properly using encodeURIComponent.
// QS will decode them for you once you request for these tokens:
QS('http://www.somedomain.com/somepage?email=nire0510%40gmail.com').get('email');
// => '[email protected]'

QS('http://www.somedomain.com/somepage?number=345.678').get('number');
// => 345.678 // Notice that you get a number, not a string

// QS also knows how to parse arrays:
QS('http://www.somedomain.com/somepage?cars%5B%5D=BMW&cars%5B%5D=Audi').get('cars[]');
// => ['BMW', 'Audi'] // param name must end with [] if its an array

// You can also omit the URL if you want QS to parse current VALID encoded page's URL:
QS().get('someKey');
// => whatever...

// Get all query string tokens from a given VALID encoded url as an object:
QS('http://www.somedomain.com/somepage?foo=bar').getAll();
// => Object {foo: "bar"}

// Check if **foo** query string key exists:
QS('http://www.somedomain.com/somepage?foo=bar').has('foo');
// => true

Write

// Change the value of **foo** query string key:
QS('http://www.somedomain.com/somepage?foo=bar').set('foo', 2);
// => url property will be changed to "http://www.somedomain.com/somepage?foo=2"

// Add a new query string token:
QS('http://www.somedomain.com/somepage?foo=bar').set('dal', 'mon');
// => url property will be changed to "http://www.somedomain.com/somepage?foo=bar&dal=mon"

// Remove a query string token:
QS('http://www.somedomain.com/somepage?foo=bar').remove('foo');
// => url property will be changed to "http://www.somedomain.com/somepage"

// Notice set & remove methods can be chained:
QS('http://www.somedomain.com/somepage?foo=bar').remove('foo').set('bar');
// => url property will be changed to "http://www.somedomain.com/somepage?bar"

Misc

// After all these URL modifications you might want to navigate to the new URL; just call `go`:
QS('http://www.somedomain.com/somepage?foo=bar').remove('foo').set('bar').go();
// => navigate to "http://www.somedomain.com/somepage?bar"

// Log all query string tokens:
QS('http://www.somedomain.com/somepage?foo=bar').log();
// => Object {foo: "bar"}

// Print current version:
QS.version;
// => '0.4.7'