querystringify
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Querystringify is a remarkably lightweight and efficient query string parser. Designed to extract the essence of simplicity, the parser aids in transforming query strings into objects. While it may not cater to deeply nested or multi-level query strings, it's perfect for straightforward tasks requiring the processing of simple query strings.
Incorporating Querystringify into your project couldn't be easier, whether you're working in a server-side or client-side environment. Firstly, install the npm module using the following CLI command: npm install --save querystringify
.
Subsequent to the module's installation, remember to incorporate it into your project:
'use strict';
var qs = require('querystringify');
Querystringify offers two main methods: parse()
and stringify()
.
parse()
method converts a given query string into an object, indifferent to prefix variations (?
, #
or none.) Here are some examples:qs.parse('?foo=bar'); // renders -> { foo: 'bar' }
qs.parse('#foo=bar'); // renders -> { foo: 'bar' }
qs.parse('foo=bar'); // renders -> { foo: 'bar' }
qs.parse('foo=bar&bar=foo'); // renders -> { foo: 'bar', bar: 'foo' }
qs.parse('foo&bar=foo'); // renders -> { foo: '', bar: 'foo' }
stringify()
function transforms an object into a query string. By default, the query string is returned without a ?
prefix. Include a true
as second parameter to get the prefix by default. Additionally, you could supply a string as second parameter, representing your custom prefix:qs.stringify({ foo: bar }); // renders -> foo=bar
qs.stringify({ foo: bar }, true); // renders -> ?foo=bar
qs.stringify({ foo: bar }, '#'); // renders -> #foo=bar
qs.stringify({ foo: '' }, '&'); // renders -> &foo=
The Querystringify documentation and additional details concerning the parser's use and functionality can be found on its GitHub repository unshiftio/querystringify. For detailed interaction and use, get into the nitty-gritty of the readme document offered by the usefulness-packed repository.