qs-objects

0.1.2 • Public • Published

qs-objects

Easily manipulate these query strings!

Installation

To install:

npm install qs-objects

Usage

Let's say we have this form:

<form action="/" method="post">
    <input type="text" name="potato[size]" value="big" />
    <input type="text" name="potato[taste]" value="good" />
    <input type="text" name="author" value="mr big" />
    <input type="submit" />
</form>

Here's an example of the request received by this form's POST:

var qsObjects = require('qs-objects');

// query string coming from the form
var querystring = 'potato%5Bsize%5D=big&potato%5Btaste%5D=good&author=mr+big';

var body = qsObjects(querystring);

// outputs full converted objects
console.log(body);

// {
//      potato: { 
//                  size: 'big', 
//                  taste: 'good' 
//              }, 
//      author: 'mr big' 
//  }

// so now you can do body.potato.taste !

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.2
    6
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.2
    6
  • 0.1.1
    3
  • 0.1.0
    3

Package Sidebar

Install

npm i qs-objects

Weekly Downloads

7

Version

0.1.2

License

none

Last publish

Collaborators

  • tbergeron