rackstring
A drop-in replacement for Node's querystring
module that parses query strings as Rack does, with support for nested objects and nested arrays.
Why?
There are a couple of popular alternatives to Node's querystring
module, namely qs
and query-string
. Unfortunately:
query-string
chooses not to support nested objects (objects in arrays).qs
does not parse objects nested in arrays quite yet; see https://github.com/ljharb/qs/issues/215.
At Code Climate, we use Rack (vis-a-vis Rails) to handle web requests. Many of our client-to-server transactions rely on conforming query string formats, and neither alternative module supports parsing complex query strings in a Rack-compliant way. I explored forking qs
and adding an option to support this sort of parsing, but adding this support proved to be non-trivial. Hence, rackstring
was born.
Installation
npm install rackstring ---save
Usage
Parsing query strings
const querystring = const obj = querystringassert
As promised, rackstring
supports parsing bracket-formatted arrays:
const obj = querystringassert
Additionally, rackstring
parses complex arrays:
const obj = querystringassert
Stringifying objects
const str = querystringassert
Optionally, you can URL-encode keys with the encodeKeys
option:
const str = querystringassert
License
See LICENSE.