victorteokw / query-string-parser

Rack style query string parser for Node.js
MIT License
8 stars 1 forks source link

Query String Parser Build Status

This simple and small js library parses url query string into object and vice versa.

It works with rack style (Ruby on Rails and Sinatra style) query string.

Usage

Node.js environment

var parser = require('query-string-parser')
parser.toQuery(yourObject)
parser.fromQuery(yourQueryString)

Browser environment

paramObject = {
  posts: [
    {
      'title': 'Post 1',
      'tags': ['node', 'script', 'javascript']
    },
    {
      'title': 'Post 2',
      'tags': ['node', 'why', 'not']
    }
  ],
  author: "Somebody",
  date: "Today"
}
queryString = toQuery(paramObject)
=>  "posts%5B%5D%5Btitle%5D=Post%201&posts%5B%5D%5Btags%5D%5B%5D=node&posts%5B%5D%5Btags%5D%5B%5D=script&posts%5B%5D%5Btags%5D%5B%5D=javascript&posts%5B%5D%5Btitle%5D=Post%202&posts%5B%5D%5Btags%5D%5B%5D=node&posts%5B%5D%5Btags%5D%5B%5D=why&posts%5B%5D%5Btags%5D%5B%5D=not&author=Somebody&date=Today"

parseQuery(queryString)
=> And the object comes back

Change log

Contribution

If you find any bugs or you want any features, please open issue or submit pull request.