qs

WebJar for qs

License

License

MIT
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

qs
Last Version

Last Version

0.3.10
Release Date

Release Date

Type

Type

jar
Description

Description

qs
WebJar for qs
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/nire0510/qs

Download qs

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/qs/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>qs</artifactId>
    <version>0.3.10</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/qs/
implementation 'org.webjars.bower:qs:0.3.10'
// https://jarcasting.com/artifacts/org.webjars.bower/qs/
implementation ("org.webjars.bower:qs:0.3.10")
'org.webjars.bower:qs:jar:0.3.10'
<dependency org="org.webjars.bower" name="qs" rev="0.3.10">
  <artifact name="qs" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='qs', version='0.3.10')
)
libraryDependencies += "org.webjars.bower" % "qs" % "0.3.10"
[org.webjars.bower/qs "0.3.10"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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.8'

Versions

Version
0.3.10